几分钟前,我正在 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.
我的网站名称是: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: }
该 Web 服务的一切正常。
那么这个错误是什么,我该如何解决?
该 Web 服务中只有一个返回 true 的简单 bool 方法。
我正在代码隐藏中使用该网络服务,如下所示:
private void CheckForPageExpiration()
{
MyService service = new MyService();
if (service.MyWebSiteEnable())
{
}
else
{
Response.Redirect("~/blank.aspx");
}
}
我删除了那个 web 服务并再次添加它,但仍然有那个错误!
这有什么问题吗?
提前致谢
最佳答案
This表明问题是代理服务器不支持来自服务器的 100-continue 响应,并显示了解决它的代码。这可以解释为什么它可以在另一个网络上工作。
由于您不太可能说服您的 ISP 改变他们的做法(尽管在请求中没有害处),您应该关闭发送 100-Continue 的行为,如链接所建议的:
将此代码放在网络请求之前:
System.Net.ServicePointManager.Expect100Continue = false;
或者,将以下行作为 <configuration> 的子项添加到应用程序配置文件中标签:
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
关于c# - 请求失败,HTTP 状态为 417 : Expectation Failed - Using Web Services,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11198393/