接口:
[OperationContract]
[WebGet(UriTemplate = "GetAll",
BodyStyle = WebMessageBodyStyle.Wrapped)]
List<Custom> GetAll();
//自定义是edmx / mssql中的实体
我是基于接口和数据库(Add service reference
表)在VisualStudio类中由Custom
工具生成的
App.config中:
<?xml version="1.0" encoding="utf-8"?>
<system.serviceModel>
<services>
<service name="CustomService" behaviorConfiguration="rest">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="" behaviorConfiguration="webHttpBehavior"
contract="ICustomService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="rest">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户端:
WebChannelFactory<ICustomService> cf = new WebChannelFactory<ICustomService>(
new Uri("http://172.30.1.2/Design_Time_Addresses/ICustomService"));
ICustomService channel = cf.CreateChannel();
var result = channel.GetAll();//here I get exception
如何正确使用此方法?