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

时间:2015-03-26 13:24:10

标签: c# .net wcf rest 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了吗?看起来类似于this但不确定如何调试以及要确认或继续的日志。最后,这是我的服务方法定义

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

1 个答案:

答案 0 :(得分:0)

问题在于地址元素。应该像

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