当我使用以下配置运行 WCF 服务时,我想从我的 VS2010 运行 WCF 服务。
<system.serviceModel>
<services>
<service name="WcfSample.Service1" behaviorConfiguration="servicebehaviour1">
<endpoint address ="http://localhost:8080/service1/Service1.svc" contract="WcfSample.IService1" binding="wsHttpBinding"></endpoint>
<endpoint address="" binding="mexHttpBinding" contract ="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="servicebehaviour1">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />-->
我收到如下异常
No protocol binding matches the given address 'http://localhost:8080/service1/Service1.svc'. Protocol bindings are configured at the Site level in IIS or WAS configuration.
如果我想在我给定的地址运行我的 WCF,我应该这样做。
最佳答案
WCF 服务的托管不采用您在配置文件的端点中定义的地址
<endpoint
address="http://localhost:8080/service1/Service1.svce"
所以你定义的上面一个是不正确的,而不是你需要做的如下
您的服务地址是 Web 服务器和虚拟目录加上 SVC 文件名,如下所示
http://servername/vrirualdirectoryname/svcfiename.svc/
您可以定义如下相对地址:
<service name="WcfSample.Service1">
<endpoint name=""
address="ServiceAddress"
binding="wsHttpBinding"
contract="WcfSample.IService1" />
</service>
所以最后你消费服务的服务地址是
http://servername/vrirualdirectoryname/svcfiename.svc/ServiceAddress
所以像这样你可以做而不是直接指定地址。
注意:
上面的代码表明服务将托管在 IIS 服务器上。
关于wcf - WCF :No protocol binding matches the given address 中的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14291715/