C#无法将cookiecontainer分配给asmx web服务客户端
我正在尝试使用visual studio 2012 express连接到C#中的asmx web服务 文档中说要将cookiecontainer分配给web服务,如下所示:C#无法将cookiecontainer分配给asmx web服务客户端,c#,web-services,cookies,soap,C#,Web Services,Cookies,Soap,我正在尝试使用visual studio 2012 express连接到C#中的asmx web服务 文档中说要将cookiecontainer分配给web服务,如下所示: using System.Web.Services.Protocols; /// using appropriate references using System.Net; using System.Net.Http; // Create an instance of the Web Service and a
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;
但是,这会导致错误:
'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?)
我已尝试将“allowCookies”添加到app.config。这似乎不起作用;调用需要登录(具有cookie集)的ws方法失败。Fail意味着我收到一条关于他们返回的xml有问题的消息(他们可能返回了一些非xml错误)
我对C#、基于SOAP的web服务和visualstudio是完全陌生的,但我见过许多代码示例使用与我完全相同的代码。例如:
您似乎正在使用一个不包含
CookieContainer
属性的WCF服务引用
客户端
实际上包含处理WCF服务引用
客户端上的cookie的方法,最简单的是allowCookies
config属性,它将自动传递在以前的响应中收到的cookie
如果您想使用较旧类型的客户端(
Web参考
,具有CookieContainer
属性),您可以遵循。您是如何添加服务参考的?WSClient对象是否有您的WebService方法?从主菜单“项目”、“添加服务引用”,然后输入指向.asmx页面的url。是的,我可以调用webservice提供的登录方法和ping方法。该服务提供的所有其他方法都需要登录。allowCookies应自动将Cookie设置为您在以前的响应中收到的Cookie。这是您想要的还是您正在使用预定义值手动设置它们?我忘了在我的回答中提到它。另外,asmx服务在你的控制之下吗?不,我只是一个消费者。我尝试过“allowCookies”,但由于我的app.config中已经有另一个绑定,所以它不起作用。我删除了“name”和“config”绑定选项,现在似乎可以工作了。