zoukankan      html  css  js  c++  java
  • WCF中使用HttpContext.Current的办法

    正常方法创建的WCF服务,就是在asp.netk中的.SVC后缀的

    是无法使用httpcontext.current等信息的

    解决办法就是在服务前加上个标识:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]   

    此标识是加在服务的class前的..不是接口中

    别忘了引用 System.ServiceModel.Activation.dll

    和在类上面using System.ServiceModel.Activation;

    还需要在web.config中加入aspNetCompatibilityEnabled="true" 
    例如:
    <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />          
            </behavior>        
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
      </system.serviceModel>

    这样WCF服务就可以用WEB特性了

    例如:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.ServiceModel.Activation;

    namespace Kingsoft.Attachment.Web
    {
        // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Attachment”。
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]     
        public class WCFAttachment : IServer.IAttachment
        {

    Powered By D&J (URL:http://www.cnblogs.com/Areas/)
  • 相关阅读:
    ASP.NET Web API编程——客户端调用
    .Net多线程编程—使用Visual Studio 2012进行调试
    .Net多线程编程—误用点分析
    中国省市区数据mysql脚本
    swift/IOS 多线程使用
    swift 自定义TabBarItem
    swift 动画切换View心地层次顺序
    swift 用协议实现代理传值功能
    Swift简单新闻APP实例
    swift NSMutableArray 排序
  • 原文地址:https://www.cnblogs.com/Areas/p/2186667.html
Copyright © 2011-2022 走看看