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方式访问了.

  • 相关阅读:
    JQuery中的bind()和unbind()的理解
    一行代码实现数组去重(ES6)
    vue.js学习笔记(Vuejs——组件——props数据传递)
    判断一个字符串书否存在某个字符,取出一段字符串括号中的内容
    在vue中使用高德地图vue-amap
    在egg.js中使用mongodb
    使用Element的upload上传组件,不使用action属性上传
    下载和安装mongodb4.2.0+robmongo可视化工具
    数组对象根据某个属性取出重复的个数
    钉钉小程序----使用阿里的F2图表
  • 原文地址:https://www.cnblogs.com/cppfans140812/p/7743451.html
Copyright © 2011-2022 走看看