WCF服務GET、POST請求接口的配置

一、接口

1,GET 配置

[OperationContract]

        [WebGet(UriTemplate = "/GetUser/{data}")]

        string GetUser (string data);

 

2,POST配置

        [OperationContract]

        [WebInvoke(Method = "POST",

                   BodyStyle = WebMessageBodyStyle.WrappedRequest)]

        string AddUser(string data);

 

data和返回值一般爲json字符串。


二、配置文件

<?xmlversion="1.0"?>

<configuration>

  <system.serviceModel>

    <diagnosticsperformanceCounters="All"/>

    <services>

      <servicename="RDIFramework.ServiceAdapter.POSService">

        <endpointaddress="http://localhost:8000/POSService"binding="webHttpBinding"contract="RDIFramework.IService.IPOSService">

        </endpoint>

        <endpointaddress="http://localhost:8000/POSService/mex"binding="mexHttpBinding"contract="IMetadataExchange" />

      </service>

    </services>

    <serviceHostingEnvironmentaspNetCompatibilityEnabled="true"

 multipleSiteBindingsEnabled="true" />

 

    <behaviors>

      <serviceBehaviors>

        <behaviorname="Internet">

         <serviceMetadatahttpGetEnabled="false" />

        </behavior>

        <behavior>

         <serviceMetadatahttpGetEnabled="True"/>

         <serviceDebugincludeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

 

    <bindings>

      <basicHttpBinding>

        <bindingname="httpBindings">

         <securitymode="None"/>

        </binding>

      </basicHttpBinding>

    </bindings>

  </system.serviceModel>

  <startup>

    <supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.0"/>

  </startup>

</configuration>


三、啓動服務

WebServiceHost factory = newWebServiceHost(“服務”,”地址”);

               factory.Open();


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章