Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IIS下的WCF RESTful Web服务-URL重写(获取404错误)_Wcf_Iis_Url Rewriting - Fatal编程技术网

IIS下的WCF RESTful Web服务-URL重写(获取404错误)

IIS下的WCF RESTful Web服务-URL重写(获取404错误),wcf,iis,url-rewriting,Wcf,Iis,Url Rewriting,我有一个WCF RESTful web服务(使用webHttpBinding)在IIS下运行,通过SVC文件(在访问时)公开 我可以使用BlarghService.svc文件,通过每个服务上定义的URI模板访问服务端点,如下所示: http://projectserver/BlarghService/BlarghService.svc/accounts/ http://projectserver/BlarghService/BlarghService.svc/accounts/342432 这

我有一个WCF RESTful web服务(使用webHttpBinding)在IIS下运行,通过SVC文件(在访问时)公开

我可以使用BlarghService.svc文件,通过每个服务上定义的URI模板访问服务端点,如下所示:

http://projectserver/BlarghService/BlarghService.svc/accounts/
http://projectserver/BlarghService/BlarghService.svc/accounts/342432
这两个都很好

但是,从URI中删除实现细节很重要,因此我使用了IIS URI重写模块,并设置了一个通配符重写规则,该规则将/BlarghService/之后的所有内容添加到BlarghService.svc的末尾,因此以下内容转换为早期表示:

http://projectserver/BlarghService/accounts/
http://projectserver/BlarghService/accounts/342432
然而,当我请求这些资源时,我得到404个错误。这些不是IIS生成的404错误,而是ASP.NET本身生成的错误(因此IIS正确地重写了URL)。但是,ASP.NET决定检查指定的文件(“BlarghService.svc/accounts/342432”)是否存在于文件系统中,并将其传递给我的web服务

但奇怪的是,当我将报告的“请求的URL”(来自ASP.NET404错误)复制回地址栏时,它工作正常

发生了什么事

编辑:这是我的web.config(位于“BlarghService”目录中)



更新:事实证明,WCF一次只能对一个特定的HTTP主机头进行响应,而我的URL重写涉及对某些主机头的响应,而不是对其他主机头的响应。通过对一组主机标题进行标准化,并相应地重新制定我的重写规则,它开始工作。

检查以确保您没有使用除wcf调用之外试图提交的aspx按钮或表单。另外,如果您没有使用.ajax和jQuery调用wcf服务,我强烈建议您采用这种方法。web服务中没有任何ASP.NET组件。我在从web浏览器获取重写URL的请求时出错。你能发布你的URL重写匹配模式和重写URL吗?我已经编辑了我的帖子,以显示web.config.Dai的相关部分,已经很长时间了,但也许你还可以分享更多详细信息?您是否还有固定的重写规则可以共享?我也遇到了同样的问题,如果能理解如何解决它,我将非常高兴。@Ivan我的webservice/IIS网站被绑定到“”和“”-我决定删除“www.fooservice.com”的绑定,而“fooservice.com”的绑定工作正常。谢谢,Dai!我将挖掘Wireshark重写的HTTP请求和直接HTTP请求之间的差异。找到问题的根本原因-IIS对*.svc文件使用本地处理程序,必须在本地Web.config()中删除它
<system.web>
    <compilation debug="true" />
    <authentication mode="None" />
    <customErrors mode="Off" />
</system.web>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <!-- Currently ASP.NET steps in says it's a 404 error when it should be handled by BlarghService.svc, I've no idea why. -->
    <rewrite>
        <rules>
            <rule name="BlarghServiceRewriteRule" patternSyntax="Wildcard">
                <match url="*" />
                <action type="Rewrite" url="BlarghService.svc/{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
        <baseAddressPrefixFilters>
            <add prefix="http://projectserver/BlarghService" />
        </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
    <services>
        <service name="Foo.Blargh.Api.BlarghService" behaviorConfiguration="BlarghServiceBehavior">

            <endpoint name="BlarghEndpoint" address="BlarghService.svc" behaviorConfiguration="BlarghEndpointBehavior" binding="webHttpBinding" contract="RH.Blargh.Api.BlarghService" />

        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="BlarghServiceBehavior">
                <serviceMetadata httpGetEnabled="false" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="BlarghEndpointBehavior">
                <webHttp />
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>