当我使用以下配置运行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,我应该这样做。
答案 0 :(得分:3)
托管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服务器上。