C# 请求失败,HTTP 状态为 417:期望失败 - 使用 Web 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11198393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The request failed with HTTP status 417: Expectation Failed - Using Web Services
提问by SilverLight
some minutes ago i was working on a project in visual studio 2010 and suddenly my pc was restarted.
after rebooting i got the error below when browsing that web site in local machine:
几分钟前,我正在 Visual Studio 2010 中处理一个项目,突然我的电脑重新启动。
重新启动后,我在本地机器上浏览该网站时出现以下错误:
The request failed with HTTP status 417: Expectation Failed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The request failed with HTTP status 417: Expectation Failed.
请求失败,HTTP 状态为 417:预期失败。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.Net.WebException:请求失败,HTTP 状态为 417:预期失败。
my web site's name is : MyWebSite
i have a web service on a remote server (a vps) that MyWebSite is using it and that error is in relationship with it.
我的网站名称是:MyWebSite
我在远程服务器(vps)上有一个 Web 服务,MyWebSite 正在使用它,并且该错误与它有关。
Line 172: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/MyWebSiteEnable", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 173: public bool MyWebSiteEnable() {
Line 174: object[] results = this.Invoke("MyWebSiteEnable", new object[0]);
Line 175: return ((bool)(results[0]));
Line 176: }
every thing is ok about that web service.
so what is this error and how can i fix it?
there is just a simple bool method inside that web service that returns true.
and i am using that web servive in code-behind like below :
该网络服务一切正常。
那么这个错误是什么,我该如何解决?
该 Web 服务中只有一个简单的 bool 方法返回 true。
我在代码隐藏中使用该网络服务,如下所示:
private void CheckForPageExpiration()
{
MyService service = new MyService();
if (service.MyWebSiteEnable())
{
}
else
{
Response.Redirect("~/blank.aspx");
}
}
i removed that web service and add it again, but still have that error!
what is wrong about that?
我删除了那个 Web 服务并再次添加它,但仍然有那个错误!
这有什么问题?
thanks in advance
提前致谢
采纳答案by Michael
Thissuggests that the problem is a proxy server that does not support a 100-continue response from the server, and shows code for resolving it. This would explain why it works on another network.
这表明问题是代理服务器不支持来自服务器的 100-continue 响应,并显示了解决它的代码。这将解释为什么它可以在另一个网络上工作。
Since you are unlikely to convince your ISP to change their practice (no harm in a request though), you should turn off the behavior of sending a 100-Continue as the link suggests by either:
由于您不太可能说服您的 ISP 改变他们的做法(尽管对请求没有害处),您应该关闭发送 100-Continue 的行为,如链接所示:
Putting this code before an web request:
将此代码放在 Web 请求之前:
System.Net.ServicePointManager.Expect100Continue = false;
Or, adding the following lines to the applications configuration file as a child of the <configuration>tag:
或者,将以下行作为<configuration>标记的子项添加到应用程序配置文件中:
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
回答by Armaan
Add below line of code in your config file.
在您的配置文件中添加以下代码行。
<system.net>
<defaultProxy useDefaultCredentials="true" >
</defaultProxy>
</system.net>

