【问题标题】:Run time error in WCF :No protocol binding matches the given addressWCF 中的运行时错误:没有协议绑定与给定地址匹配
【发布时间】:2013-01-12 08:37:34
【问题描述】:

当我使用以下配置运行 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" />-->

我遇到如下异常

没有协议绑定与给定地址“http://localhost:8080/service1/Service1.svc”匹配。协议绑定在 IIS 或 WAS 配置中的站点级别进行配置。

如果我想在我给定的地址运行我的 WCF,我应该怎么做。

【问题讨论】:

标签: wcf


【解决方案1】:

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 服务器上。

【讨论】:

    猜你喜欢
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2011-03-11
    相关资源
    最近更新 更多