Search code examples
c#web-servicesclientcookiescookiecontainer

Adding a cookie to web service port client


I'm using a web service in my app that requires a specific cookie to be set in order access it's methods.

I was using a generated wrapper class for that service that was created using wsdl.exe tool. Everything is working ok using that method.

// this is the instance of object generated with wsdl.exe
WSWrapper service = new WSWrapper(); 

// set cookie
service.CookieContainer = new CookieContainer();    
Cookie cookie = new Cookie(name, value, path, domain);
service.CookieContainer.Add(cookie);

// run method requiring cookie to be set
service.Test(); 

Now I wanted to do something similar using Service Reference instead of pre-generated class. I added web reference but there seems to be no CookieContainer (or anything similar) in service reference port client that was generated.

Does anyone knows how to add a cookie to that client?


Solution

  • I solved the problem. Instead of creating Service Reference I added Web Reference and the generated client had all the properties of the wsdl.exe pre-generated class.