When adding WebService Reference to an ASMX Service on a .NET 2.0 project for example,
var objService = new NameSpace.groupservices();
there exists,
objService.CookieContainer = new System.Net.CookieContainer();
When adding ServiceReference to an ASMX Service on a .NET 4.0 project for example,
var objService = new NameSpace.groupservicesSoapClient();
there isn't any CookieContainer property for objService
A similar question was asked here with no positive solution.
Could someone please guide where to find the property?
Open your app.config file and add allowCookies="true" to the binding.
Something like this:
In contrast to ASMX Web Services that are tied to HTTP transport, WCF allows for various transport protocols to be used. Therefore, not all protocol-specific options (such as Cookies for HTTP transport) are available in a WCF service reference.
You can, however, add a message inspector that inspects the messages that are sent between client and server. This article describes a way to send cookies to the server.
I've extended the sample to use a CookieContainer. Also, the following code shows how to evaluate the
Set-Cookie
header sent by the server to add the new cookies to the container. Please note that the sample shows a basic outline, but might need extension or some more validation. However, in a simple scenario it worked.The following snippet shows a test method of a WCF service that is hosted on IIS and integrated in the ASP.NET framework. It basically echoes the cookies sent to the server in a string and adds two new ones:
The following test program creates a CookieContainer for the cookies, adds a demo cookie and registers a new behavior for the endpoint of the service:
The behavior serves the purpose of adding a custom message inspector and handing over the CookieContainer:
The message inspector both adds cookies when a request is sent to the server in the
BeforeSendRequest
method and retrieves the cookies that should be updated in theAfterReceiveReply
method. Note that thecorrelationState
returned byBeforeSendRequest
is used to retrieve the Uri in theAfterReceiveReply
:Found the solution in here:
http://msdn.microsoft.com/en-us/library/bb628649.aspx
It turns out I need a web reference instead of a service reference