【问题标题】:WCF Service Operation - GET Fails with 404WCF 服务操作 - GET 失败并出现 404
【发布时间】:2010-11-07 17:04:59
【问题描述】:

我有一个 WCF 服务,可以在运行 IIS 7 的开发机器上运行,但我的同事运行的是 IIS 5.1 (XP)。当他导航到服务页面时,他可以在 Web 浏览器中查看服务,但如果他尝试调用操作或在 Web 浏览器中导航到该操作,则会收到 404 错误。

我让他运行 ServiceModelReg -i,但这并没有改变任何东西。我让他导航到 .svc?wsdl 页面,该方法在此处列出。但是当他尝试导航到该方法(它使用 WebGetAttribute)时,IIS 返回 404。有什么想法吗?

更新

只有当他从 IIS 运行站点时才会出现问题。如果他使用 Visual Studio Web Server (cassini) 加载项目,它工作正常。

我认为问题不在于服务本身,但以防万一:

    [ServiceContract]
public interface IPFDClientAuthentication {
    [OperationContract]
    [WebGet(UriTemplate="/Logon?username={username}&password={password}",
        BodyStyle=WebMessageBodyStyle.WrappedResponse,
        ResponseFormat=WebMessageFormat.Json)]
    [JSONPBehavior(callback="callback")]
    bool Logon(string username, string password);

    [OperationContract]
    [WebGet(UriTemplate = "/Logout",
        BodyStyle = WebMessageBodyStyle.WrappedResponse,
        ResponseFormat = WebMessageFormat.Json)]
    [JSONPBehavior(callback = "callback")]
    bool Logout();

    [OperationContract]
    [WebGet(UriTemplate="/GetIdentityToken",
        BodyStyle=WebMessageBodyStyle.WrappedRequest,
        ResponseFormat=WebMessageFormat.Json)]
    [JSONPBehavior(callback= "callback")]
    string GetIdentityToken();
}

这是 web.config:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
    <service behaviorConfiguration="PFD.AuthenticationService.PFDClientAuthenticationBehavior"
                     name="PFD.AuthenticationService.PFDClientAuthentication">
        <endpoint address="" behaviorConfiguration="PFD.AuthenticationService.PFDClientEndpointBehavior"
                         binding="customBinding" bindingConfiguration="clientBinding"
                         name="clientEndpoint" contract="PFD.AuthenticationService.IPFDClientAuthentication">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
</services>
<bindings>
    <customBinding>
        <binding name="clientBinding">
            <jsonpMessageEncoding/>
            <httpTransport manualAddressing="true"/>
        </binding>
    </customBinding>
</bindings>
<behaviors>
    <endpointBehaviors>
        <behavior name="PFD.AuthenticationService.PFDClientEndpointBehavior">
            <webHttp />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
        <behavior name="PFD.AuthenticationService.PFDClientAuthenticationBehavior">
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
    </serviceBehaviors>
</behaviors>
<extensions>
    <bindingElementExtensions>
        <add name="jsonpMessageEncoding" type="Microsoft.Ajax.Samples.JsonpBindingExtension, 
                 PFD.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </bindingElementExtensions>
</extensions>

【问题讨论】:

    标签: wcf http-status-code-404


    【解决方案1】:

    在 XP 机器上的 IIS 中添加通配符映射。将*.* 映射到 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 并取消选中“验证文件存在”复选框。

    根据您的 REST 网址的格式,您可能需要使用 .* 而不是 *.*(您的网址看起来像目录还是像文件?)

    【讨论】:

    • 谢谢,我的同事暂时不在,所以我无法真正验证修复,但我认为你是对的。我忘记了脚本映射。
    • 我不得不问,因为我遇到了同样的问题。您是否确认这是答案,或者您是否将其标记为假设它会起作用的答案?
    【解决方案2】:

    尝试在服务 URL 末尾添加/soap

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-16
      • 2022-08-08
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多