0

界面:

[OperationContract]
[WebGet(UriTemplate = "GetAll",
BodyStyle = WebMessageBodyStyle.Wrapped)]
List<Custom> GetAll();

//自定义是edmx/mssql中的实体

我已经Add service reference在基于接口和数据库(Custom表)的 VisualStudio 类中通过工具生成

应用程序配置:

<?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

如何正确使用这种方法?

4

0 回答 0