一、接口
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();