当前位置: 首页 > news >正文

WCF和IIS宿主的ASP.NET 共享会话

1. 建立WCF工程

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
31
32
33
34
35
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Runtime.Serialization;
using  System.ServiceModel;
using  System.Text;
using  System.Web;
using  System.ServiceModel.Activation;
 
namespace  WCFASPSession
{
     [AspNetCompatibilityRequirements(RequirementsMode =
         AspNetCompatibilityRequirementsMode.Allowed)]
     public  class  Service1 : IService1
     {
        
         public  int  Add( int  value)
         {
             int  result = GetResult() + value;
 
             HttpContext.Current.Session[ "Result" ] = result;
 
             return  result;
         }
 
         public  int  GetResult()
         {
             if  (HttpContext.Current.Session[ "Result" ] == null )
             {
                 HttpContext.Current.Session[ "Result" ] = 0;
             }
             return  ( int )HttpContext.Current.Session[ "Result" ];
         }
     }
}

2. 在web工程里建一个.svc文件

1
<%@ ServiceHost Language= "C#"  Debug= "true"  Service= "WCFASPSession.Service1"   %>

3. 修改web.config

主要是添加<serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment> ,还有allwoCookies一定要设为true.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<system.serviceModel>
     <bindings>
       <wsHttpBinding>
         <binding name= "WSHttpBinding_IService1"   closeTimeout= "00:01:00"
           openTimeout= "00:01:00"  receiveTimeout= "00:10:00"  sendTimeout= "00:01:00"
           bypassProxyOnLocal= "false"  transactionFlow= "false"  hostNameComparisonMode= "StrongWildcard"
           maxBufferPoolSize= "524288"  maxReceivedMessageSize= "65536"  messageEncoding= "Text"
           textEncoding= "utf-8"  useDefaultWebProxy= "true"  allowCookies= "true" >
           <readerQuotas maxDepth= "32"  maxStringContentLength= "8192"  maxArrayLength= "16384"
             maxBytesPerRead= "4096"  maxNameTableCharCount= "16384"  />
           <reliableSession ordered= "true"  inactivityTimeout= "00:10:00"
             enabled= "false"  />
           <security mode= "Message" >
             <transport clientCredentialType= "Windows"  proxyCredentialType= "None"
               realm= ""  />
             <message clientCredentialType= "Windows"  negotiateServiceCredential= "true"
               algorithmSuite= "Default"  />
           </security>
         </binding>
       </wsHttpBinding>
     </bindings>
     <client>
       <endpoint address= "http://localhost:8000/Service1.svc"  binding= "wsHttpBinding"
         bindingConfiguration= "WSHttpBinding_IService1"  contract= "ServiceReference1.IService1"
         name= "WSHttpBinding_IService1" >
         <identity>
           <dns value= "localhost"  />
         </identity>
       </endpoint>
     </client>
     <serviceHostingEnvironment aspNetCompatibilityEnabled= "true" ></serviceHostingEnvironment>
     <services>
       <service name= "WCFASPSession.Service1" >
         <endpoint address= ""  binding= "wsHttpBinding"  contract= "WCFASPSession.IService1" >
           <!--
               Upon deployment, the following identity element should be removed or replaced to reflect the
               identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
               automatically.
           -->
           <identity>
             <dns value= "localhost" />
           </identity>
         </endpoint>
         <!-- Metadata Endpoints -->
         <!-- The Metadata Exchange endpoint is  used by  the service to describe itself to clients. -->
         <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
         <endpoint address= "mex"  binding= "mexHttpBinding"  contract= "IMetadataExchange" />
       </service>
     </services>
     <behaviors>
       <serviceBehaviors>
         <behavior>
           <!-- To avoid disclosing metadata information,
           set  the value below to false  and remove the metadata endpoint above before deployment -->
           <serviceMetadata httpGetEnabled= "True" />
           <!-- To receive exception details in  faults for  debugging purposes,
           set  the value below to true .  Set to false  before deployment
           to avoid disclosing exception information -->
           <serviceDebug includeExceptionDetailInFaults= "False" />
         </behavior>
       </serviceBehaviors>
     </behaviors>
   </system.serviceModel>
<a href= "http://files.cnblogs.com/cnblogsfans/WCFASPSession.rar" >Demo Sample source code</a>
本文转自敏捷的水博客园博客,原文链接http://www.cnblogs.com/cnblogsfans/archive/2010/05/18/1738227.html如需转载请自行联系原作者

王德水

相关文章:

  • ORDER BY,GROUP BY 和DI STI NCT 优化
  • JS中字符串转义
  • 【SSH网上商城项目实战03】使用EasyUI搭建后台页面框架
  • ORA-00119: invalid specification for system parameter LOCAL_LISTENER;
  • Mybatis介绍
  • USB数据采集卡:labjack T7、T7 Pro系列的技术特点
  • Mocha测试初探
  • 在线修改ha.proxy配置文件
  • BZOJ 4016: [FJOI2014]最短路径树问题
  • Flask的sqlalchemy SQL练习
  • js通过按钮直接把input或者textarea里的值复制到粘贴板里
  • SpringBoot基础篇配置信息之多环境配置信息
  • Horizon for NSX 服务安装包
  • bootstrap-带下拉菜单的标签页
  • 再下一城:Google 成为 Safari 默认搜索引擎
  • 深入了解以太坊
  • Docker: 容器互访的三种方式
  • Electron入门介绍
  • JavaScript 基础知识 - 入门篇(一)
  • JavaScript 奇技淫巧
  • JavaScript实现分页效果
  • Webpack 4 学习01(基础配置)
  • 得到一个数组中任意X个元素的所有组合 即C(n,m)
  • 基于组件的设计工作流与界面抽象
  • 排序(1):冒泡排序
  • 算法之不定期更新(一)(2018-04-12)
  • LevelDB 入门 —— 全面了解 LevelDB 的功能特性
  • #NOIP 2014# day.1 生活大爆炸版 石头剪刀布
  • %3cli%3e连接html页面,html+canvas实现屏幕截取
  • (07)Hive——窗口函数详解
  • (1综述)从零开始的嵌入式图像图像处理(PI+QT+OpenCV)实战演练
  • (Bean工厂的后处理器入门)学习Spring的第七天
  • (ZT)一个美国文科博士的YardLife
  • (二)换源+apt-get基础配置+搜狗拼音
  • (翻译)Entity Framework技巧系列之七 - Tip 26 – 28
  • (附源码)springboot家庭装修管理系统 毕业设计 613205
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (黑马C++)L06 重载与继承
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (原創) 如何優化ThinkPad X61開機速度? (NB) (ThinkPad) (X61) (OS) (Windows)
  • (转)关于如何学好游戏3D引擎编程的一些经验
  • ***利用Ms05002溢出找“肉鸡
  • *上位机的定义
  • .NET BackgroundWorker
  • .NET Core 2.1路线图
  • .Net转Java自学之路—基础巩固篇十三(集合)
  • /deep/和 >>>以及 ::v-deep 三者的区别
  • /etc/skel 目录作用
  • [ HTML + CSS + Javascript ] 复盘尝试制作 2048 小游戏时遇到的问题
  • [ 云计算 | AWS 实践 ] 基于 Amazon S3 协议搭建个人云存储服务
  • [1181]linux两台服务器之间传输文件和文件夹
  • [16/N]论得趣
  • [17]JAVAEE-HTTP协议
  • [20140403]查询是否产生日志
  • [acm算法学习] 后缀数组SA