ksoap2消费与净会议服务 [英] ksoap2 consuming .Net service with sessions
问题描述
的getMessages是我的聊天程序的方法我有一个.NET Web服务。它得到消息的集合,只有通过保存的最后一条消息ID在会话变量发送新的。
GetMessages is a method I have in a .net web service for my chat program. It gets a collection of messages, only sending new ones by saving the last message ID in a session variable.
HeaderProperty mSessionHeader = null;
public SoapObject GetMessages()
{
...
SoapObject request = new SoapObject(NAMESPACE, METHOD);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.V11);
envelope.dotNet = true;
envelope.bodyOut = request;
HttpTransport transport = new HttpTransport(URL);
transport.debug = true;
// Build request header
LinkedList<HeaderProperties> reqHeaders = new LinkList<HeaderProperties>();
if (mSessionHeader != null) {
reqHeaders.add(mSessionHeader); //using the session id from last header
}
List<HeaderProperties> respHeaders = transport.call(ACTION, envelope, reqHeaders);
// See note after code
for (HeaderProperty hp : respHeaders) {
if (hp.getKey().equalsIgnoreCase("set-cookie"))
{
mSessionHeader = hp;
break;
}
}
return (SoapObject) envelope.getResponse();
}
mSessionHeader的价值是一样的东西。
the value of mSessionHeader is something like
设置Cookie:ASP.NET_SessionId = 0zzfwxxp1sakeafybjzsxp0k;路径= /;仅Http
set-cookie: ASP.NET_SessionId=0zzfwxxp1sakeafybjzsxp0k; path=/; HttpOnly
不过,GUID部分更改为... transport.call每次调用()结果
当我使用相同的标题(通过将如mSessionHeader == NULL周围的for循环)
它仍然无法正常工作......的方法获取不管发送的每一封邮件
我的位置在Web服务设置
However, the GUID part changes every call to ... transport.call()
When I use the same header (by putting if mSessionHeader == null around the for loop)
it still does not work... the method gets every message sent regardless of the
position i set in the Web Service
我一定要添加更多的报头,然后就在ASP.NET_SessionId?
Do I have to add more headers then just the ASP.NET_SessionId?
推荐答案
我很惊讶,没有一个答案,这个要求......反正我找到了。
I'm surprised there isn't demand for an answer to this... anyways I found it.
请求头发送的cookie是从响应不同 -
The request header to send a cookie is different from the response -
请求
曲奇:ASP.NET_SessionId = #####
"Cookie: ASP.NET_SessionId=#####"
响应
设置Cookie:ASP.NET_SessionId = #####
"Set-Cookie: ASP.NET_SessionId=#####"
所以上面的线 -
reqHeaders.add(mSessionHeader);
被更改为
reqHeaders.add(new HeaderProperty("Cookie", mSessionHeader.getValue());
这篇关于ksoap2消费与净会议服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!