c# - 无法公开地址处的 WCF 端点

标签 c# web-services wcf iis wsdl

问题

我无法通过端点指定的地址公开 WCF 服务。

示例我的端点地址是:http://localhost:36793/services/main

当我使用 Visual Studio 托管 WCF 服务并尝试访问该地址时,我收到 http 404 错误(未找到)。

我期望能够通过将 ?wsdl 应用到地址末尾来查看地址的 WSDL。

第二个奇怪的事情是我可以通过在地址中指定 SVC 来访问该地址。

示例:http://localhost:36793/ServiceManager.svc?wsdl

环境

  • Windows 8.1
  • Visual Studio 2013 更新 1
  • IIS Express 通过 Visual Studio 托管 Web 服务

想法

我知道这要么是 Web 服务的配置问题,要么是 IIS 中未完全配置的内容。

任何帮助将不胜感激,我花了相当多的时间试图解决这个问题。请参阅下面的我的 Web 配置。

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
 <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <client />
    <services>
  <service behaviorConfiguration="MexTypeBehaviour" name="Server.ServiceManager">
    <clear />
    <endpoint address="Main" binding="basicHttpBinding" name="Main" contract="Server.IServiceManager" />
    <endpoint address="Mex" binding="mexHttpBinding" name="Mex" contract="Server.IServiceManager" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:36793/services" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
   <serviceBehaviors>
    <behavior name="MexTypeBehaviour" >
        <serviceMetadata httpGetEnabled="true" />
    </behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"     />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
         To browse web app root directory during debugging, set the value below to true.
         Set to false before deployment to avoid disclosing web app folder information.
     -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

最佳答案

如果 WCF 服务由 IIS 托管,则 *.svc 的位置真正决定服务 URL - 不是 <host>/<baseAddresses> 中的任何设置或<endpoint>

您的服务基础 URL 是 http://yourservername:36793/ServiceManager.svc - 并且您不能通过在配置中指定其他内容来更改它。

既然您定义了 Main您的服务的相对地址,您应该能够调用您的服务方法:

http://localhost:36793/ServiceManager.svc/Main

The second strange thing is that I am able to get access to the address by specifying the SVC in the address.

这并不奇怪 - 这是嵌入到 WCF 中的 IIS 托管行为。这是一个功能 - 而不是错误。

如果您希望能够自由定义服务 URL,则需要使用自托管提供控制台应用程序或 Windows 服务来托管您的 WCF 服务基础结构。

关于c# - 无法公开地址处的 WCF 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24984231/

相关文章:

c# - 我可以在同一服务中使用 PerCall 实例化和可重入并发吗?

c# - 为什么来自 asp.net c# 应用程序的 Web 服务调用返回 null?

c# - 如何将 WCF 模板添加到 Visual Studio Express?

c# - 在属性上设置绑定(bind)时是否会触发事件?

c# - C# 中的线程。可中断任务

java - 如何在 Ubuntu 中为 Java 5/Tomcat 5.5 编译 .war?

web-services - Java EE 7 GlassFish 4.0 Restful Webservices 使用 Netbean 并在 Glassfish 4.0 上部署

c# - 带有计数器的错误日志

c# - Unity 构建太大的立方体贴图

web-services - Delphi Web 服务如何工作? (在运行时添加方法??)