部署后WCF Web服务无法正常工作

时间:2012-04-27 13:41:29

标签: wcf visual-studio-2010 web-services

我正在尝试创建一个WCF Web服务,该服务允许其他应用程序通过向此服务URL发出http请求来检索字符串。我尝试在IIS中发布服务,当尝试浏览它时,使用url,它说它

' The resource cannot be found'

当我检查文件夹的路径时,我使用了网址, 我收到了错误

'No protocol binding matches the given address 
'http://localhost:xxxx/WcfSampleLibrary/Service1/mex.' 
 Protocol bindings are configured at the Site level in IIS or WAS configuration'

以下是已发布文件夹的目录路径:

C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\WcfSampleLibrary.Service1
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\Web.config
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\bin\WcfSampleLibrary.dll

网络配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<system.web>
    <compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
  <service name="WcfSampleLibrary.Service1" behaviorConfiguration ="mex">
    <host>
      <baseAddresses>
        <add baseAddress = "http://192.xxx.x.xxx/WcfSampleLibrary/Service1/" />
      </baseAddresses>
    </host>
    <!-- Service Endpoints -->
    <endpoint address ="" 
      binding="wsHttpBinding"  contract="WcfSampleLibrary.IService1">
     <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <!-- Metadata Endpoints -->
   <endpoint address="http://localhost:xxxx/WcfSampleLibrary/Service1/mex" name="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mex">
     <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="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

1 个答案:

答案 0 :(得分:3)

在IIS托管的WCF服务中,您不在地址中指定完整的URI。 IIS决定地址。在IIS中托管时,baseAddresses元素也会被完全忽略(因此将其从Web.config中删除)。该服务的基地址由网站&amp;你的wcf服务所在的虚拟目录。做这样的事情:

  <endpoint
    address="mex"
    binding="mexHttpBinding"
    contract="IMetadataExchange"
  />

然后您的地址为http://IIS.SERVER/SiteName/Folder/WcfSampleLibrary.Service1.svc。如果您不确定地址是什么,请使用IIS管理工具,选择包含该服务的站点,右键单击并选择“高级” - >浏览网站。

另外,如果你想发布你的WSDL,我会在你的mex行为上打开httpGetEnabled。这使您在开发服务时更容易使用服务:

<behaviors>
  <serviceBehaviors>
    <behavior name="mex" >
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

启用httpGetEnabled后,浏览到您的服务URI将为您提供查看WSDL的选项。