Reputation: 45
I'm attempting to connect to a asmx web service in C# using visual studio 2012 express.
The documentation says to assign a cookiecontainer to the web service like follows:
using System.Web.Services.Protocols; /// using appropriate references
using System.Net;
using System.Net.Http;
// Create an instance of the Web Service and assign in
// a cookiecontainer to preserve the validated session
ServiceRef.WSClient wsClient = new ServiceRef.WSClient();
CookieContainer cookieJar = new CookieContainer();
wsClient.CookieContainer = cookieJar;
But, that results in error:
'WebServiceTest.ServiceRef.WSClient' does not contain a definition
for 'CookieContainer' and no extension method 'CookieContainer'
accepting a first argument of type 'WebServiceTest.ServiceRef.WSClient'
could be found (are you missing a using directive or an assembly
reference?)
I've tried adding "allowCookies" to app.config. That doesn't seem to work; calling ws methods that require being logged in (having a cookie set) fail. Fail means I get a message about a problem with the xml they return (they're returning some non-xml error presumably).
I'm totally new to C#, SOAP based web services, and visual studio, but I've seen numerous code examples that use code exactly like mine. For example:
http://megakemp.com/2009/02/06/managing-shared-cookies-in-wcf/
Upvotes: 3
Views: 4544
Reputation: 1488
It seems that you are using a WCF service reference
client that doesn't contain a CookieContainer
property.
The post that you referenced actually contains methods for dealing with cookies on WCF service reference
clients, The simplest being the allowCookies
config property, which would automatically pass cookies that were received in previous responses.
If you would like to use the older types of clients (Web Reference
, which have the CookieContainer
property) you can follow this article.
Upvotes: 2