RaYell
RaYell

Reputation: 70414

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?

Upvotes: 2

Views: 6802

Answers (2)

Surpdeh
Surpdeh

Reputation: 81

There are advantages to the svcutil.exe generated proxies though.

Having the client save and return the cookies returned by the server (as used to be done by simply adding a CookieContainer) can now be controlled through app.config. Add allowCookies="true" to the basicHttpBinding or basicHttpsBinding as an attribute to the binding.

Alternatively use the WCF configuration editor to do the same.

Upvotes: 4

RaYell
RaYell

Reputation: 70414

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.

Upvotes: 0

Related Questions