C# 无法在地址处公开WCF终结点

C# 无法在地址处公开WCF终结点,c#,web-services,wcf,iis,wsdl,C#,Web Services,Wcf,Iis,Wsdl,问题 我无法通过端点指定的地址公开WCF服务 例如,我的终点地址是:http://localhost:36793/services/main 当我使用VisualStudio托管WCF服务并尝试访问该地址时,我收到一个http 404错误(未找到) 我希望能够通过将?WSDL应用到地址的末尾来查看地址的WSDL 第二件奇怪的事情是,我能够通过在地址中指定SVC来访问地址 示例:http://localhost:36793/ServiceManager.svc?wsdl 环境 Windows 8

问题

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

例如,我的终点地址是:
http://localhost:36793/services/main

当我使用VisualStudio托管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,而不是
/
中的任何设置

您的服务基础URL是
http://yourservername:36793/ServiceManager.svc
-您不能通过在配置中指定其他内容来改变这一点

由于您已经为您的服务定义了
Main
相对地址,您应该能够在

http://localhost:36793/ServiceManager.svc/Main
第二件奇怪的事情是,我能够通过在地址中指定SVC来访问地址

这并不奇怪-是IIS托管行为被烘焙到WCF中。这是一个功能——不是一个bug


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

我认为您正在托管visual studio中的服务,该服务将自动启动IIS express。在IIS中承载服务时,配置中指定的基址将被忽略

.svc文件确定服务的基址-

定义
mex
端点时,您的配置也不正确

<endpoint address="Mex" binding="mexHttpBinding" name="Mex" contract="Server.IServiceManager" />

您可以从代码中使用每个端点,但地址、契约、绑定、安全性和任何其他方面都必须匹配。

您的服务是从visual studio(自托管)还是从IIS托管的?您是如何使用浏览器提供的服务的?来自不同的机器?这已经解释了很多,谢谢你的时间和努力。谢谢你的反馈,似乎是这样的!
http://localhost:36793/ServiceManager.svc/Main
http://localhost:36793/ServiceManager.svc/Mex