例外:远程服务器返回意外响应:(405)方法不允许

时间:2013-10-22 15:46:29

标签: c# winforms wcf wcf-rest service-reference

接口:

[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

如何正确使用此方法?

0 个答案:

没有答案