【发布时间】:2013-06-24 03:56:22
【问题描述】:
我正在尝试使用 Visual Studio 2012 Express 连接到 C# 中的 asmx Web 服务。
文档说要为 Web 服务分配一个 cookie 容器,如下所示:
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 方法失败。失败意味着我收到一条关于他们返回的 xml 问题的消息(他们可能返回了一些非 xml 错误)。
我对 C#、基于 SOAP 的 Web 服务和 Visual Studio 完全陌生,但我见过大量使用与我的代码完全相同的代码示例。例如:
http://megakemp.com/2009/02/06/managing-shared-cookies-in-wcf/
【问题讨论】:
-
您是如何添加服务引用的? WSClient 对象有你的 WebService 方法吗?
-
从主菜单,“项目”,“添加服务参考”,然后输入指向.asmx页面的url。是的,我可以调用webservice提供的登录方法和ping方法。该服务提供的所有其他方法都需要登录。
-
allowCookies 应该使用您在之前的响应中收到的 cookie 自动设置 cookie。这是您想要的还是您使用预定义的值手动设置它们?我忘了在我的回答中提到它。
-
还有,asmx服务在你的控制之下吗?
-
不,我只是一个消费者。
标签: c# web-services cookies soap