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

  • 相关阅读:
    面向对象OO第15次作业总结
    面向对象OO第9-11次作业总结
    一文讲完最基本的图算法——图的存储、遍历、最短路径、最小生成树、拓扑排序
    字符串匹配问题的KMP算法
    提问回顾与个人总结
    软工结对作业—最长单词链
    软工第1次个人作业
    软工第0次个人作业
    OO最后一次作业
    JSF生存指南P1
  • 原文地址:https://www.cnblogs.com/cppfans140812/p/7743451.html
Copyright © 2011-2022 走看看