“CookieContainer”在哪里?进入 Visual Studio 2008/2010 Web 服务吗? (WCF中的会话cookie持久化)
这似乎是一个非常简单的问题,但是经过在这里和网上几个小时的研究后,我开始认为我可能问了错误的问题或做了错误的事情。
无论如何,我有一个用于登录的Web服务,一旦成功,就会返回一个标头cookie,随后使用此cookie调用其他服务将被视为已通过身份验证。这可能不是最安全或最佳实践,但这是我在 Java 中提供的服务
,我只是从成功登录的响应中获取 cookie 并传递给其他调用,
例如(我知道,有些调用已被弃用,并且 Axis 1 已完全弃用,但请发挥您的想象力)
// get the cookie
Call authCall = service1Locator.getCall();
org.apache.axis.MessageContext msgContext = authCall.getMessageContext();
String cookie = msgContext.getStrProp(HTTPConstants.HEADER_COOKIE);
// Standard binding
Service2Locator service2Locator=new Service2Locator();
Service2SoapBindingStub service2=(Service2SoapBindingStub)service2Locator.getSomeService();
service2Locator.setMaintainSession(true);
// And now - SET THE COOKIE
service2._setProperty(HTTPConstants.HEADER_COOKIE,cookie);
(原始示例来自 此处)
至于它可能是旧的、不正确的或不安全的(是吗?),我想在.NET中仍然做同样的事情
我看到 评论 CookieContainer,但我的服务(由 VS Express 2010 自动生成)没有这样的属性...
从一个服务调用获取 cookie 并传递给另一个服务的等效方法是什么(效仿浏览器会自动执行一些会话持久性)
(如果可能的话,我仍然想使用简单的“添加服务引用”自动生成的 Web .NET 服务客户端)
It seems like a very simple question, but after a couple of hours of research in here and on the web, I'm starting to think I'm perhaps asking the wrong questions or doing something wrong.
In any case, I have a web service that is used for logging-in, once successful, a header cookie is returned, and subsequent calls to other services using this cookie will be considered as authenticated. It may not be the safest or best practice, but this is the service I have
In Java, I’m simply taking the cookie from the response of the successful login and pass to other calls
e.g. (I know, some calls are deprecated, and Axis 1 is deprecated altogether, but use your imagination)
// get the cookie
Call authCall = service1Locator.getCall();
org.apache.axis.MessageContext msgContext = authCall.getMessageContext();
String cookie = msgContext.getStrProp(HTTPConstants.HEADER_COOKIE);
// Standard binding
Service2Locator service2Locator=new Service2Locator();
Service2SoapBindingStub service2=(Service2SoapBindingStub)service2Locator.getSomeService();
service2Locator.setMaintainSession(true);
// And now - SET THE COOKIE
service2._setProperty(HTTPConstants.HEADER_COOKIE,cookie);
(original example from here)
As far as it may be old, incorrect or insecure (is it?), I would like to still do the same thing in .NET
I saw comments on CookieContainer, but my service (auto generated by VS Express 2010) doesn't have such a property...
What is the equivalent way to get a cookie from one service call and pass to the other (to emulate some session persistence as a browser would do automatically)
(I still want to use the simple "add service reference" auto generated web .NET service client if possible)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是一个很好的答案
http://jonas.follesoe.no/2008/09/12/wcf-authentication-services-silverlight-and-smelly-cookies/
另外这个问题也提到了它如何使用身份验证 cookie来自 ASP.Net MVC 应用程序中的 WCF 身份验证服务
This seems like a good answer
http://jonas.follesoe.no/2008/09/12/wcf-authentication-services-silverlight-and-smelly-cookies/
Also this question which referred to it How to use authentication cookie from WCF Authentication Service in an ASP.Net MVC application