【问题标题】:WCF web service not working after deployed部署后 WCF Web 服务不工作
【发布时间】:2012-04-27 21:58:50
【问题描述】:

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

' The resource cannot be found'

当我检查我使用 url 的文件夹的路径时, 我得到了错误

'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>

【问题讨论】:

  • 您已将其发布到同一台机器上的 IIS 并设置为侦听端口 xxxx?
  • 您的baseAddress 与您的服务端点address 不同。通常你可以省略baseAddressaltoggether。
  • 我没有设置端口,只想使用服务器ip地址;它自己设置端口
  • 如果我删除了 baseAddress,我可以更改端点地址以使用其中的 ip,以便可以从 LAN 内访问它

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


【解决方案1】:

在 IIS 托管的 WCF 服务中,您没有在地址中指定完整的 URI。 IIS 决定地址。在 IIS 中托管时,baseAddresses 元素也会被完全忽略(因此请从您的 Web.config 中删除它)。服务的基地址由放置 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 的选项。

【讨论】:

  • 感谢您的解释...我尝试了更改,但现在出现错误:Web 服务器配置为不列出此目录的内容...在 IIS 中使用浏览站点时。当我在浏览器中手动输入整个 url 时,它返回找不到资源……这只是一个安全/共享问题。还有
  • IT 可能不会列出目录的内容(您可以在 IIS 管理员中将其打开),但至少您可以获得 Web 服务器用来托管它的 URI。 web文件夹中有哪些文件?你有ServiceName.svc 文件吗?
  • 服务文件不在web文件夹中;我在 bin 文件夹中有 WcfSampleLibrary.dll,在主文件夹中有 web.config 文件。我应该手动添加服务文件吗?
  • 是的。还要确保 .svc 文件引用了 bin/ 文件夹中的 .DLL。所以你的 .svc 文件的第一行有:&lt;%@ ServiceHost Language="C#" Service="Namespace.And.Name.Of.Assembly"%&gt; Service 的值应该是在 bin 文件夹中引用你的程序集。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-26
  • 1970-01-01
  • 2013-11-24
  • 2017-07-02
相关资源
最近更新 更多