繁体   English   中英

自托管WCF服务引发错误消息“ 405方法不允许”

[英]Self Hosted WCF Service throws Error Message “405 Method not allowed”

我有一个自托管WCF服务,它看起来像这样:

[ServiceContract]    
public interface IService {
    [OperationContract]     
    [WebGet]   
    List<Data> GetData();
    //...and much more Methods
}

我的App.config看起来像这样:

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MetaInformation">
        <serviceMetadata httpGetEnabled="true"
                         httpGetUrl="http://localhost:8500/MetaInfo"
                         httpsGetBinding="" />
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="EndpointBehavior">
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <services>     
    <service behaviorConfiguration="MetaInformation" name="Library.WcfService.ServiceModel">
      <endpoint address="http://localhost:8500/Service"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBindingSettings"
                contract="Library.WcfService.IService"
                bindingName="BasicHttpBindingSettings"
               behaviorConfiguration="EndpointBehavior"/>                        
    </service>
  </services>
  <bindings>      
    <basicHttpBinding>
      <binding name="BasicHttpBindingSettings"
               closeTimeout="00:50:00"
               openTimeout="00:50:00"
               sendTimeout="00:50:00"
               maxBufferSize="524288"
               transferMode="Streamed"
               maxReceivedMessageSize="2147483647"
               maxBufferPoolSize="2147483647"
               messageEncoding="Text">
        <readerQuotas maxDepth="2147483647"
                      maxStringContentLength="2147483647"
                      maxArrayLength="2147483647"
                      maxBytesPerRead="2147483647"
                      maxNameTableCharCount="2147483647" />
      </binding>
    </basicHttpBinding>
  </bindings>
</system.serviceModel>

<system.web>
  <httpRuntime maxRequestLength="102400"/>    
</system.web>

当我在本地计算机上运行此服务器和客户端应用程序时,它工作正常。 但是,当我尝试在另一台PC上运行服务器应用程序时,无法在客户端添加服务引用,因为我得到了以下信息:

405不允许使用的方法元数据包含无法解析的引用:“ http://192.168.178.54:8500/MetaInfo ”。 这不是在听可以接受该消息的http://192.168.178.54:8500/MetaInfo端点。 这通常是由错误的地址或SOAP操作引起的

我几乎尝试了在互联网上找到的所有内容,但没有任何效果。 切换到IIS或使用其他协议应该是计划B,我想让它与http自托管。

请有人可以帮我我对这个问题感到绝望。

您的操作合同带有[WebGet]属性,这意味着您正尝试将服务公开为REST 但是您的服务使用basicHttpBinding作为构建通信通道的方式,因此不支持该方法,因为此绑定的内容类型为soap+xml 在这种情况下,您将需要使用WebHttpBinding ,这是唯一支持WebHttpBinding实现WCF Services并支持XmlJson数据类型的绑定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM