在 SOAP 客户端中实现会话 [英] Implementing session in SOAP Client

查看:30
本文介绍了在 SOAP 客户端中实现会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 WP 应用程序,该应用程序使用 SOAP 客户端在 .NET 中实现了 Web 服务.我已经使用添加服务引用"选项在我的 WP 应用中实现了 SOAP 客户端.

I am developing a WP application for which the webservices are implemented in .NET using SOAP client. I have implemented the SOAP client in my WP app using "Add service reference" option.

现在的问题是,有两种不同的客户端类,一种用于登录功能,另一种用于所有其他查询.登录工作正常,返回 true 或 false,没有别的.另一个客户端类用于进行不同的查询,这些查询都工作正常并从服务器获取一些数据.经过测试,我观察到响应与登录用户无关(即服务器发送与登录用户无关的相同数据).因此很明显会话没有被维护并且服务器正在发送一些匿名数据.

Now the problem is, there are two different client classes one for the Login functionality and the other for all other queries. Login is working fine and returning me true or false and nothing else. And the other client class is used to make different queries which are all working fine and getting some data from server. After testing I observed that the response is independent of the logged in user( ie server sending same data irrelevant of the logged in user). And hence it is clear that the session is not maintained and the server is sending some anonymous data.

有人帮助我如何在 SOAP 客户端中维护会话.

Some one help me on how to maintain the session in the SOAP client.

注意:我无法就此询问网络服务提供商.:(

Note: I cannot ask the web service providers on this. :(

推荐答案

我终于想出了如何在 Windows 手机应用程序中维护基于 cookie 的会话

Finally I figured out how to maintain cookie based session in Windows phone apps

感谢 Mike 的指导.

Thanks to Mike for his guidance.

对于那些想知道在 WP 应用程序中维护会话的不同方式的人,有一个名为 CookieContainer 的类,它有助于为我们维护 cookie 数据.

For all those who are wondering about the different ways of maintaining session in WP app, there is a class called CookieContainer which helps to maintain cookie data for us.

用法:

首先创建 CookieContainer 类的全局实例(我在 App.xaml.cs 中创建的)

First create a global instance of CookieContainer class ( I created in App.xaml.cs)

//In App.xaml.cs
CookieContainer cookieContainer = new CookieContainer();

然后将其分配给我们从应用程序向服务器发出的每个请求.

And then assign it to every request we make to the server from our app.

MySoapClient client = new MySoapClient();
client.CookieContainer = (App.Current as App).cookieContainer;
client.LoginAsync("username", "password");

再次针对应用中的任何其他请求

Again for any other request in the app

MyOtherSoapClient anotherClient = new MyOtherSoapClient();
anotherClient.CookieContainer = (App.Current as App).cookieContainer;
anotherClient.PostDataAsync("somedata");

同样的规则也适用于普通的 WebClientHttpWebRequest 类.

The same rule also applies for normal WebClient and HttpWebRequest classes also.

快乐编码:)

这篇关于在 SOAP 客户端中实现会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆