[CF.Skills]在.NET Compact Framework中设置webservice的session状态

.NET CF中没有Cookie Container之类方便管理cookie的类,我刚刚简单的搜索了一下,找到一段用作Session管理器的代码:(原文见这里)
        /// <summary>
        
/// This field contains the received session cookie
        
/// </summary>

        private string cookie = null;

        
/// <summary>
        
/// Http-Header for the request SessionCookie
        
/// </summary>

        private const string REQUESTHEADER_SESSIONCOOKIE = "Cookie";

        
/// <summary>
        
/// Http-header for the response SessionCookie
        
/// </summary>

        private const string RESPONSEHEADER_SESSIONCOOKIE = "Set-Cookie";

        
private void ProcessResponse(System.Net.HttpWebResponse response)
        
{
            
// Is the cookie present in the response?
            if (response.Headers.Get(RESPONSEHEADER_SESSIONCOOKIE) != null)
            

                
// Store the cookie
                cookie = response.Headers.Get(RESPONSEHEADER_SESSIONCOOKIE);
            }

        }


        
/// <summary>
        
/// This override will tweak the request to allow Session-cookies
        
/// </summary>
        
/// <returns>The tweaked request</returns>

        protected override System.Net.WebRequest GetWebRequest(Uri uri)
        
{
            System.Net.HttpWebRequest request 
= (System.Net.HttpWebRequest)base.GetWebRequest(uri);

            
// Is the session cookie cached?
            if (cookie != null)
            

                
// Add the sessioncookie to the request
                request.Headers.Add(REQUESTHEADER_SESSIONCOOKIE, cookie);
            }

            
return request;
        }


        
/// <summary>
        
/// This override will tweak the response to allow Session-cookies
        
/// </summary>

         protected override System.Net.WebResponse GetWebResponse(System.Net.WebRequest request)
        
{
            System.Net.HttpWebResponse response 
= (System.Net.HttpWebResponse)base.GetWebResponse(request);
            ProcessResponse(response);
            
return response;
        }


        
/// <summary>
        
/// This override will tweak the response to allow Session-cookies
        
/// </summary>

        protected override System.Net.WebResponse GetWebResponse(System.Net.WebRequest request, IAsyncResult result)
        
{
            System.Net.HttpWebResponse response 
= (System.Net.HttpWebResponse)base.GetWebResponse(request, result);
            ProcessResponse(response);
            
return response;
        }

除了这种人工控制请求应答的消息头的方式,不知道在.NET CF中大家还有哪些方案来维系webservice的会话,不妨一同探讨一下:-)

Regards

黄季冬

posted on 2008-04-29 18:47 Freesc Huang 阅读(545) 评论(3) 编辑 收藏

评论

#1楼 2008-06-22 02:03 江南白衣      

请问这有什么具体的应用嘛?  回复 引用 查看   

#2楼 2009-04-13 16:50 chenzz[未注册用户]

你好,在.net compact framework中调用服务器端的webService(服务器端webService有登陆验证)有没有什么比较好的办法啊?这段时间一直为这个问题苦恼
我MSN是:cs_chenzz@hotmail.com,交流交流经验,请问楼主的MSN是什么呢?
 回复 引用   

<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

公告

These postings are provided "AS IS" with no warranties
and confer no rights.


Locations of visitors to this page

Blog Keywords
Embedded System,Visual Studio,.Net Framework,.Net Compact Framework,.Net Micro Framework,Windows Mobile,Windows Embedded CE,Emulator,WCF,CLR,Design & Pattern,C/C++,C#,Matlab,Algorithms
昵称:Freesc Huang
园龄:4年11个月
粉丝:32
关注:4

统计

  • 随笔 - 197
  • 文章 - 0
  • 评论 - 840

搜索

 

随笔分类(227)

随笔档案(197)

Blogs

Link

积分与排名

最新评论

阅读排行榜

评论排行榜

推荐排行榜