WCF Web 服务部署后不工作

标签 wcf visual-studio-2010 web-services

我正在尝试创建一个 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 托管的 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 的选项。

关于WCF Web 服务部署后不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10351714/

相关文章:

wcf - 从.net core调用Service Fabric

c# - Visual Studio 的 Web 性能测试可以用作 Web 场的压力测试吗?

c# - vs2010/c#中的表命名空间错误

visual-studio-2010 - 臭名昭著的程序集绑定(bind)错误

ios - 应用程序使用 swift 使用 API 时会崩溃吗?

C# REST 客户端示例?

.net - 在 WCF 服务库项目中在哪里设置和存储应用程序状态?

.net - 在ASP.NET Core网站中使用Reporting Services(SSRS)作为引用

asp.net - 仅在 ASP.net 内部用于 AJAX 消耗的 ASMX 或 WCF

web-services - ServiceClass 对象未实现以下形式的所需方法 : OMElement login(OMElement e)