黄季冬=>fox23
Freesc Huang
&
Windows Embedded
博客园
首页
新随笔
联系
订阅
管理
数据加载中……
[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
fox23
阅读(167)
评论(2)
编辑
收藏
所属分类:
Winbile Skills
评论
#1楼
2008-06-22 02:03
江南白衣
请问这有什么具体的应用嘛?
回复
引用
查看
社区
新闻
新用户注册
刷新评论列表
标题
姓名
主页
Email
(只有博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关文章:
.NET设计模式系列文章
编译调试CSLA .NET Framework v1.5
prototype.js 1.4版开发者手册(强烈推荐)
ASP.NET AJAX入门系列
使用Visual Studio2005入门.Net2.0系列视频教程
ASP.NET 大文件上传组件[无组件上传](AspnetUpload 2.3 release)[免费版序列号放送中...]
相关链接:
所属分类的其他文章:
Windows Mobile进阶系列.WCF Mobile(Part 3 & final)
在Windows Mobile 5,6 的设备上使用ActiveSync Remote Display
为什么要使用模拟器?
[CF.Skills]播放嵌入资源的声音文件
[CF.Skills]WinCE互操作时传递托管控件句柄的小技巧
[CF.Skills]防止Smartphone进入休眠状态
[CF.Skills]在.NET Compact Framework中设置webservice的session状态
[CF.Skills]Windows Mobile如何编程实现免提功能
[CF.Skills]托管代码在Smartphone上创建快捷方式
[CF.Skills]Windows Mobile上设置只读但是可选择内容的textBox
最新IT新闻:
福布斯:IE8很多功能针对谷歌 微软要玩偷袭
施密特:谷歌计划十月份开始推进与雅虎合作
微软加快XP专业版反盗版步伐
Mozilla与谷歌续签三年搜索合同
CBS推出新版CNET重推视频
博客园新闻频道
博客园首页
社区
公告
Freesc Huang
.Net Micro Framework
MII - Microsoft
Embedded System & Hardware Platform Lab
These postings are provided "
AS IS
" with no warranties, and confer no rights.
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#
<
2008年6月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
统计
随笔 - 116
文章 - 0
评论 - 492
引用 - 72
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(25)
给我留言
查看留言
我管理的小组
.NETCompactFramework
我参加的小组
程序员音乐空间
博客园上海俱乐部
Windows Embedded
CLR基础研究小组
博客园精华集出版小组
我参与的团队
Design & Pattern团队(1/849)
.Net 商业智能(0/393)
.NET 控件与组件开发(1/1362)
北京.NET俱乐部(1/1465)
Windows Mobile 应用开发(0/579)
CLR基础研究团队(0/380)
Windows Embedded开发(0/91)
开源CLI核心探索团队(0/87)
WCF技术研究团队(0/148)
随笔分类
(129)
.NET MF&SPOT(7)
(rss)
C#.NET(17)
(rss)
C/C++ on Linux
(rss)
C/C++ on Windows(2)
(rss)
Embedded Sys(4)
(rss)
MCU
(rss)
Multimedia(1)
(rss)
News&CoolStuff(13)
(rss)
OTs(9)
(rss)
Robotics
(rss)
Software Design(1)
(rss)
Thinkin' in CLR(8)
(rss)
Winbile Dev(30)
(rss)
Winbile Skills(30)
(rss)
Windows CE(4)
(rss)
数字通信原理(3)
(rss)
收藏夹
Winbile
(rss)
Blogs
.Net CFTeam
.Net MFTeam
appleseeker
Bob Li
ctacke
mikehall
MobileTeam
Nasiry 's way
songtitan
vincentzhou
老葛
(rss)
刘洪峰
马宁
张欣
Link
hust
My live space
winbile
OtherCoolBlogs
Allen Lee
(rss)
jeffreyzhao
jillZhang
lbq1221119
积分与排名
积分 - 99680
排名 - 386
最新随笔
1. 提问的智慧 - How To Ask Questions The Smart Way
2. Skyfire:支持 Silverlight 的手机浏览器
3. .Net Micro Framework 模拟器详解---内存配置
4. 在Windows Mobile的应用程序中选择图标的大小
5. learn C++ or C# Options
6. Windows Mobile上的GPRS连接(基于TcpClient)
7. .Net Micro Framework 模拟器详解 – 基本原理
8. SQL Server Compact 3.5 SP1 RTM发布了!
9. GPS Programming Tips for Windows Mobile
10. 在.Net Micro Framework中访问硬件 - part3
11. 数据交换=>Windows_Mobile+WCF+Exchange2007 - part2
12. 数据交换=>Windows_Mobile+WCF+Exchange2007 - part1
13. 更快地查找Windows Embedded CE的BSP!
14. Live Search for Windows Embedded CE 6.0
15. .NET Micro Framework v3.0 Beta Announced!
16. The Windows Mobile Ecosystem for Developers
17. Windows Mobile进阶系列.WCF Mobile(Part 3 & final)
18. 基于.NETCompact Framework的WCF(中文MSDN更新)
19. 也说C#中的Immutable
20. [推荐]国外的Windows Mobile资源站点
最新评论
1. re: 提问的智慧 - How To Ask Questions The Smart Way
@guihua
在于平等坦诚无私地交流
--fox23
2. re: 提问的智慧 - How To Ask Questions The Smart Way
我在开发中也发现我身边的程序员有这样的问题两个程序员之间互相问问题 都是很直接 这个这个怎么实现问题是需要有上下文的 并且一定要站在对方的角度去思考 让对方明白自己在说什么 要不然说了老半天 人家还没...
--guihua
3. re: 提问的智慧 - How To Ask Questions The Smart Way
学习了
--谦虚的天下
4. re: 提问的智慧 - How To Ask Questions The Smart Way
提问和回复都应该“文明”
--陈晨
5. re: 提问的智慧 - How To Ask Questions The Smart Way
不错,学习了。
--2008年的梦想
阅读排行榜
1. Windows Mobile 进阶系列.第一回.真的了解.NET CF吗?(2760)
2. Windows Mobile 进阶系列.多窗体应用的性能与编程调试(2718)
3. [CF Skills]P/invoke in .NET Compact Framework(2454)
4. WCF for .NET CF快速入门(2441)
5. Windows Mobile 进阶系列.WCF Mobile(Part 1)(2124)
6. Windows Mobile 进阶系列.WCF Mobile(Part 2) (2072)
7. [翻译]GDI on Windows Mobile--托管代码和本地代码的性能比较(2019)
8. Windows Mobile 进阶系列.第二回.初窥.NET CF类型加载器(2016)
9. Direct Push---甚好甚强巨(1922)
10. 再谈Windows Mobile上的模拟按键操作(1913)
评论排行榜
1. [CF.Skills]在.NET Compact Framework中获取来电号码和屏蔽来电(57)
2. Windows Mobile 进阶系列.第三回.让.NET CF CLR有条不紊(35)
3. Windows Mobile 进阶系列.第一回.真的了解.NET CF吗?(25)
4. [CF.Skills]托管代码在Smartphone上创建快捷方式(23)
5. Windows Mobile 进阶系列.第二回.初窥.NET CF类型加载器(20)
60天内阅读排行
1. 在.Net Micro Framework中访问硬件 - part1(1646)
2. .Net Micro Framework 模拟器详解---内存配置(1590)
3. .Net Micro Framework 模拟器详解 – 基本原理(1530)
4. 提问的智慧 - How To Ask Questions The Smart Way(1316)
5. 在.Net Micro Framework中访问硬件 - part3(1245)
6. 也说C#中的Immutable(1166)
7. Windows Mobile进阶系列.WCF Mobile(Part 3 & final)(1082)
8. 在.Net Micro Framework中访问硬件 - part2(1046)
9. 数据交换=>Windows_Mobile+WCF+Exchange2007 - part1(864)
10. [推荐]国外的Windows Mobile资源站点(436)