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



我正在创建一个简单的WCF服务,它返回类似的东西

{"LoginResult":"您好,来自WCF(A)"}

我使用来自浏览器的打击访问服务

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完成了吗。看起来与此类似,但不确定如何调试以及确认或继续哪些日志。最后,这是我的服务方法定义

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

问题出在address元素上。应该像一样

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

最新更新