2016-05-12 80 views
0

我主持WCF服务,它看起来像这样的自我:自托管的WCF服务抛出错误消息“不允许405方法”

[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托管。

请有人可以帮助我我绝望与这个问题。

+0

你能否告诉我们在另一台计算机上安装了哪个.NET版本,以及如果你将所有需要的dll(从每个类中的使用)复制到另一台计算机的WCF-bin文件夹?可能是以太网.NET没有安装(在所需的最小版本中),或者您的GAC(全局程序集缓存)中有另一台计算机没有的东西。 –

+0

我在两台机器上都使用.NET 4.0。我只是将整个VS解决方案复制到其他PC进行调试。 当我在另一台PC上运行客户端时,它也可以工作。只有当我尝试通过LAN使用WCF服务时,才会出现此错误。 –

回答

0

您的操作合同使用[WebGet]属性进行了装饰,这意味着您试图将您的服务展示为REST。但是您的服务使用basicHttpBinding作为构建通信通道的手段,因为此绑定的内容类型为soap+xml,所以不支持此通信通道。在这种情况下,您需要使用WebHttpBinding,这是唯一支持平稳实施WCF Services并且同时支持XmlJson数据类型的绑定。

+0

我将我的App.config改为WebHttpBinding。仍然得到405错误:( –

+0

你可以发布更新的配置? –

+0

是的,它在我的答案。 –

相关问题