【问题标题】:Adding a cookie to web service port client向 Web 服务端口客户端添加 cookie
【发布时间】:2010-11-14 08:37:25
【问题描述】:

我在我的应用程序中使用了一个网络服务,它需要设置一个特定的 cookie 才能访问它的方法。

我正在为使用wsdl.exe 工具创建的该服务使用生成的包装类。使用该方法一切正常。

// 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(); 

现在我想使用服务参考而不是预先生成的类来做类似的事情。我添加了网络参考,但在生成的服务参考端口客户端中似乎没有CookieContainer(或任何类似的东西)。

有谁知道如何向该客户端添加 cookie?

【问题讨论】:

    标签: c# web-services client cookies cookiecontainer


    【解决方案1】:

    我解决了这个问题。我没有创建服务参考,而是添加了 Web 参考,生成的客户端具有 wsdl.exe 预生成类的所有属性。

    【讨论】:

      【解决方案2】:

      svcutil.exe 生成的代理虽然有一些优势。

      现在可以通过 app.config 控制让客户端保存并返回服务器返回的 cookie(过去只需添加 CookieContainer 即可完成)。将allowCookies="true" 添加到basicHttpBindingbasicHttpsBinding 作为绑定的属性。

      或者使用 WCF 配置编辑器来做同样的事情。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-04
        • 2016-06-15
        • 1970-01-01
        • 2020-10-23
        • 1970-01-01
        • 1970-01-01
        • 2013-02-03
        • 2010-11-09
        相关资源
        最近更新 更多