WCF 服务响应“HTTP/1.1 400 错误请求”在共享主机上<又名空白页 、xml 解析错误、无效地址、找不到网页>又名空白页>
这既是给遇到该问题的人的信息,也是一个问题。
编辑:问题是为什么要删除“www”。 没有“www”的情况下引用时,从 URL 中获取会导致此错误。
当在同一地址运行的网站可以在 将服务从本地 IIS 迁移到共享托管时面临的问题。
问题是在浏览器中检查网址后出现以下响应(来自 fiddler)。 在网上搜索有关该主题的帖子时,除了帖子之外,我还发现了许多指向同一问题的未解决问题常见的共享托管配置问题可以在其中修复。
HTTP/1.1 400 错误请求 服务器:微软-IIS/7.0 X-Powered-By: ASP.NET 日期:2010 年 8 月 17 日,星期二 00:27:52 GMT Content-Length: 0
在 Safari/Chrome 中,这显示为空白页面。
在 IE 中,您会收到“找不到网页”。
在 FF 中,您会收到“XML 解析错误:找不到元素位置:http://................ 第 1 行,第 1 列:”(我在许多未解决的帖子中看到了这一点)在网络上 - 请随意反向链接可能的解决方案)
在 Opera 中,您会收到“无效地址”,
我为此挠头了一段时间,然后我想尝试输入“www”。我之前没有任何特殊原因从我的网址中省略了。
问题已解决。
我现在可以在浏览器中看到正常输出,并通过 WCF 测试客户端与服务交互。
所以问题是:
为什么这会对托管的 WCF 服务产生影响当我知道它不会对浏览到网站托管在同一地址? 有或没有“www”。我可以浏览到同一帐户托管的同一域中的网站。
到目前为止,我已在 GoDaddy 服务上测试了此重现。我稍后可能会尝试其他一些。
另外,如果您碰巧知道 - 我很想知道哪些功能可能使我的 WCF 服务需要完全信任而不是中等信任。以及您对使用这些功能是否是个好主意的任何想法(在最不隐私的意识形态背景下)。
作为参考,这是 web.config,包括 Mike 建议尝试解决此问题的附加端点。
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation><!--debug="true"-->
<buildProviders>
<remove extension=".svc"/>
<add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider,System.ServiceModel, Version=3.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
</buildProviders>
</compilation>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="blah"
name="WCFServ.EvalService">
<endpoint address="http://www.abcdomain.com/WCFServ/WCFServ.EvalService.svc"
binding="basicHttpBinding"
contract="WCFServ.IEvalService" />
<endpoint address="http://abcdomain.com/WCFServ/WCFServ.EvalService.svc"
binding="basicHttpBinding"
contract="WCFServ.IEvalService" />
<!--<endpoint address=""
binding="mexHttpBinding"
contract="IMetadataExchange" />-->
<!--<host>
<baseAddresses>
<add baseAddress="http://abcdomain.com/WCFServ/" />
</baseAddresses>
</host>-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="blah">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.abcdomain.com/WCFServ/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
<!--http://localhost/WCFServ/WCFServ.EvalService.svc-->
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
This is both information to those experiencing the issue and a question.
edit: The question is why does dropping "www." from the URL cause this error when a website running at the same address can be referenced without "www.".
I recently reproduced this problem using a trivial WCF service (the one from endpoint.tv) after resolving the usual config issues one faces moving a service from local IIS to shared hosting.
The problem was the following response (from fiddler) upon checking the url in browser. In searching the web for posts on the topic I found a number of unresolved issues pointing to the same problem in addition to the posts where the usual shared hosting config issues fix them up.
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Tue, 17 Aug 2010 00:27:52 GMT
Content-Length: 0
In Safari/Chrome this manifests as a blank page.
In IE you get "The webpage cannot be found".
In FF you get "XML Parsing Error: no element found Location: http://................ Line Number 1, Column 1:" (which I saw in numerous unresolved posts on the web - feel free to backlink a possible solution)
In Opera you get "Invalid Address"
I was scratching my head regarding this for a while, then I thought to try putting in the "www." which I was previously omitting from my url for no particular reason.
Problem solved.
I can now see the normal output in the browser and interact with the service via WCF Test Client.
So the question is:
Why does this make a difference to the hosted WCF service when I know it does not make a difference for browsing to the website hosted at the same address? With or without the "www." I can browse to the website at the same domain, hosted on the same account.
So far I've tested this repro on a GoDaddy service. I may try some others later.
Also, if you happen to know - I'd be interested to know what features are likely to make my WCF services need full trust rather than medium trust. And any thoughts you have on whether it is a good idea to utilise such features (in context of least priv ideology).
For reference this is the web.config, including an additional endpoint suggested by Mike to try and resolve this.
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation><!--debug="true"-->
<buildProviders>
<remove extension=".svc"/>
<add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider,System.ServiceModel, Version=3.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
</buildProviders>
</compilation>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="blah"
name="WCFServ.EvalService">
<endpoint address="http://www.abcdomain.com/WCFServ/WCFServ.EvalService.svc"
binding="basicHttpBinding"
contract="WCFServ.IEvalService" />
<endpoint address="http://abcdomain.com/WCFServ/WCFServ.EvalService.svc"
binding="basicHttpBinding"
contract="WCFServ.IEvalService" />
<!--<endpoint address=""
binding="mexHttpBinding"
contract="IMetadataExchange" />-->
<!--<host>
<baseAddresses>
<add baseAddress="http://abcdomain.com/WCFServ/" />
</baseAddresses>
</host>-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="blah">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.abcdomain.com/WCFServ/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
<!--http://localhost/WCFServ/WCFServ.EvalService.svc-->
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您使用绝对 URL 作为终结点地址,因此 WCF 需要查看 HTTP 请求中的特定主机标头才能绑定到这些地址。
Web 服务器也不例外;如果它们是为特定主机配置的,则请求标头必须具有主机名,否则它们将不会提供内容。但是,多个主机名可以绑定到网站,因此有时一个网站可能同时绑定到 www.example.com 和 example.com。此外,如果您访问 example.com 并收到 404 错误或者 DNS 查找失败,某些 Web 浏览器将自动在 www.example.com 上重试请求。
我认为解决问题最简单的方法是修改端点,使它们与主机无关。例如:
Because you're using absolute URLs as your endpoint addresses, WCF needs to see a specific host header in HTTP requests in order to bind to those addresses.
Web servers are no different; if they're configured for a specific host, the request headers must have the host name or they won't serve up content. However, multiple host names can be bound to web sites, however, so sometimes a site may be tied to both www.example.com and example.com. Also, some web browsers, if you go to example.com and get a 404 or if the DNS lookup fails, will automatically retry the request at www.example.com.
I think the easiest thing for you to do to resolve your issue is to modify your endpoint(s) so they are host neutral. For example:
确保您在 Web 配置中定义了不带 www 的端点。
Make sure that you have endpoints defined without the www in your web config.
此页面有一些关于 WCF 寻址的很好的解释:
WCF 寻址深度。
通过在服务类中添加以下属性可以解决您的问题吗?
This page has some good explanations about WCF addressing:
WCF Adressing In Depth.
Is your problem solved by adding the following attribute on your serviceclass?