zoukankan      html  css  js  c++  java
  • WCF配置后支持通过URL进行http方式调用

    第一、app.config的配置,全局代码如下:

     
    <?xml version="1.0"?>
    <configuration>

      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name="WcfService1.Service1">
            <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding"
              contract="WcfService1.IService1" />
          </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>
          <endpointBehaviors>
            <behavior name="webBehavior">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
     
    </configuration>
     

    1.endpointBehaviors节点是后来新增且必须的

    2.注意名称webBehavior的对应关系

    3.binding="webHttpBinding"

    第二、WCF接口必须增加标记

    [OperationContract]

    [WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]

    //[WebInvoke(ResponseFormat = WebMessageFormat.Json,Method="Post",BodyStyle = WebMessageBodyStyle.Bare)]

    String SetDph(String dph);

    1.WebGet表示通过get方式访问,WebInvoke可能通过Method指定get或post

    2.BodyStyle设置为Bare就直接返回结果,如果设置为Wrapped将会自动增加些内容

    3.ResponseFormat有xml和json两种方式

    通过上面两个地方的配置之后就能够轻松的通过http方式访问了.

  • 相关阅读:
    【Oracle】dba_jobs字段说明
    【工作杂记】一次修改表字段名操作导致的报表缺失了2个小时的数据
    【SAP BO】无法识别账户信息:无法访问CMS。计算机上的CMS由于某个严重错误而停止。(FWM 20031)
    【虚拟机】在VMware中安装Server2008之后配置网络连接的几种方式
    vlc for android 编译过程
    ubuntu19更新源
    nginx错误Too many open files
    mp4流化
    编译ffmpeg的时候出现ERROR: libx264 not found
    nginx中Lua模块内置变量
  • 原文地址:https://www.cnblogs.com/cppfans140812/p/7743451.html
Copyright © 2011-2022 走看看