Restful WCF HTTP 错误 404.0 - 在 IIS 中托管时未找到

Restful WCF HTTP Error 404.0 - Not Found when hosting in IIS

我正在创建一个简单的 WCF 服务,它 returns 类似于

{"LoginResult":"Hello from WCF (A)"}

我是通过浏览器的blow访问服务的

http://localhost:50908/Service/Login/A

当 运行 来自 visual studio 本地时,它在 IIS Express 中工作得很好。但是当部署到远程 IIS 时,我得到 HTTP 错误 404.0 - 未找到 。如果我访问

,我可以查看我的服务默认页面

http://xx.xxx.xxx.xxx:8091/MyApp/Service.svc

。这是我的 Web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation targetFramework="4.5">
      <assemblies>
        <add assembly="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="MyService.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://xxx.xxx.xxx.xxx:8091/MyApp/Service" />
          </baseAddresses>
        </host>
        <endpoint address="service" binding="webHttpBinding" contract="MyService.IService1">
          <identity>
            <dns value="xxx.xxx.xxx.xxx"/>
          </identity>
        </endpoint>
        <!--endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/-->
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

我知道这可能很棘手,并试图进一步缩小根本原因的范围。尝试创建一个 tracelistener,但没有什么特别的。 servicemodelreg -i。看起来类似于 this 但不确定如何调试以及确认或继续哪些日志。最后,这是我的服务方法定义

[WebInvoke(UriTemplate = "/Login/{userName}", Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped,
        ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
    public string Login(string userName)

问题出在地址元素上。应该像

<endpoint address="" binding="webHttpBinding" contract="MyService.IService1"  behaviorConfiguration="webhttpbehavior">