简体   繁体   English

“远程服务器返回错误:(417)期望失败。”

[英]“The remote server returned an error: (417) Expectation Failed.”

i'm writing windows 8 app.(on Visiual Studio 2012) which uses my wcf service. 我正在编写使用我的wcf服务的Windows 8应用程序(在Visiual Studio 2012上)。 It works well when i try at my home, so it can connect to the wcf. 当我在家里尝试时它很好用,所以它可以连接到wcf。 But when i tried at my office, it cannot connect to wcf and returns error : 但是,当我在我的办公室尝试时,它无法连接到wcf并返回错误:

The remote server returned an error: (417) Expectation Failed. 远程服务器返回错误:(417)期望失败。

I think its causing by firewall in the office network.. Googled too much, tried a lot of however the problem still here. 我认为它是由办公室网络中的防火墙造成的..用Google搜索过多,尝试了很多,但问题仍然在这里。

System.Net.ServicePointManager.Expect100Continue = false;

Doesn't work because .Net Framework 4.5 has not ServicePointManager Class but msdn says there is ServicePointManager on .Net 4.5.. http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue.aspx 不起作用,因为.Net Framework 4.5没有ServicePointManager类,但msdn说.Net 4.5上有ServicePointManager .. http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue.aspx

<system.net>
    <settings>
        <servicePointManager expect100Continue="false" />
    </settings>
</system.net>

Cannot try this to write on web.config or app.config because win8 app has not these files.. 无法尝试在web.config或app.config上编写,因为win8应用程序没有这些文件..

some people wrote above code to devenv.exe.config file of VS 2012. I tried it but nothing changed. 有些人将上面的代码写到了VS 2012的devenv.exe.config文件中。我试了但是没有改变。

http://www.jlpaonline.com/?p=176 http://www.jlpaonline.com/?p=176

Well, you posted the question here , and Can Bilgin gave an answer. 好吧,你在这里发布了这个问题,而且Bilgin可以给出答案。 I post it here for those who have the problem than you. 我在这里发布给那些遇到问题的人。

I think it should be possible to add the header manually... I would give it a go with the operationscope... from an earlier example: 我认为手动添加标题应该是可行的......我会先从一个例子来看看操作范围...

Task<GetADGroupMemberResponse> AccountManagement.GetADGroupMemberAsync(GetADGroupMemberRequest request)
{
    // CB: Creating the OperationContext
    using (var scope = new OperationContextScope(this.InnerChannel))
    {
        // CB: Creating and Adding the request header
        var header = MessageHeader.CreateHeader("Server", "http://schemas.microsoft.com/2008/1/ActiveDirectory/CustomActions", request.Server);
        OperationContext.Current.OutgoingMessageHeaders.Add(header);

        return base.Channel.GetADGroupMemberAsync(request);
    }
}

cause on the http requests with the httpclient you can do something like (again from an earlier example): 使用httpclient在http请求上导致你可以做类似的事情(再次来自前面的例子):

var httpClient = new HttpClient(); 
var httpContent = new HttpRequestMessage(HttpMethod.Post, "http://app.proceso.com.mx/win8/login");

// NOTE: Your server was returning 417 Expectation failed, 
// this is set so the request client doesn't expect 100 and continue.
httpContent.Headers.ExpectContinue = false;

var values = new List<KeyValuePair<string, string>>(); 
values.Add(new KeyValuePair<string, string>("user", "******"));
values.Add(new KeyValuePair<string, string>("pass", "******"));

httpContent.Content = new FormUrlEncodedContent(values);

HttpResponseMessage response = await httpClient.SendAsync(httpContent);

// here is the hash as string 
var result = await response.Content.ReadAsStringAsync();

For reference, the following is a full example of using WebClient to post a JSON request to a REST webservice. 作为参考,以下是使用WebClient将JSON请求发布到REST Web服务的完整示例。 It sets the Expect100Continue flag to false , includes proxy authentication using default credentials if required, and catches non-200 response codes. 它将Expect100Continue标志设置为false ,包括使用默认凭据进行代理身份验证(如果需要),并捕获非200响应代码。

void Main()
{
    var ms = new MemoryStream();
    var ser = new DataContractJsonSerializer(typeof(Job));
    ser.WriteObject(ms, new Job { Comments = "Test", Title = "TestTitle", Id = 1 });

    var uri = new Uri("http://SomeRestService/Job");
    var servicePoint = ServicePointManager.FindServicePoint(uri);
    servicePoint.Expect100Continue = false;

    var webClient = new WebClient();
    webClient.Headers["Content-type"] = "application/json";

    IWebProxy defaultProxy = WebRequest.DefaultWebProxy;
    if (defaultProxy != null){
        defaultProxy.Credentials = CredentialCache.DefaultCredentials;
        webClient.Proxy = defaultProxy;
    }

    try {
        var result = webClient.UploadData(uri, "POST", ms.ToArray());
    } catch (WebException we) {
        var response = (HttpWebResponse)we.Response;
    }
}

[DataContract]
public class Job
{
    [DataMember (Name="comments", EmitDefaultValue=false)]
    public string Comments { get; set; }
    [DataMember (Name="title", EmitDefaultValue=false)]
    public string Title { get; set; }
    [DataMember (Name="id", EmitDefaultValue=false)]
    public int Id { get; set; }
}

Although adding this line 虽然添加了这一行
() as a setting to the config may fix the initial error you are likely to still get (504) Gateway Timeout if your proxy settings are not allowing you to use the correct open port open to your on the target server. ()作为配置的设置可以修复您可能仍然获得的初始错误(504)网关超时如果您的代理设置不允许您使用在目标服务器上打开的正确打开端口。 To add a proxy exception for the server you are sending to, add it via internet explorer as a proxy exclusion on connections tab -> LAN settings -> Advanced. 要为要发送的服务器添加代理例外,请通过Internet Explorer将其添加为连接选项卡上的代理排除 - > LAN设置 - >高级。 I hope you'll be able to connect then. 我希望你能够连接起来。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF:远程服务器返回错误:“(417)预期失败”和“(503)服务器不可用” - WCF: The remote server returned an error: '(417) Expectation Failed' and '(503) Server Unavailable' 为什么收到此错误:远程服务器返回错误:(417)预期失败 - Why do I receive this error: The remote server returned an error: (417) Expectation Failed HTTP POST 返回错误:417“期望失败”。 - HTTP POST Returns Error: 417 "Expectation Failed." 请求失败。 远程服务器返回错误:(401)连接到Office365时出现未授权错误 - The request failed. The remote server returned an error: (401) Unauthorized error while connecting to Office365 Exchange Web 服务 - 请求失败。 远程服务器返回错误:(413) 请求实体太大 - Exchange Web Services - The request failed. The remote server returned an error: (413) Request Entity Too Large EWS Oauth异常:请求失败。 远程服务器返回错误:(401)未经授权 - EWS Oauth Exception: The request failed. The remote server returned an error: (401) Unauthorized 预警系统。 请求失败。 远程服务器返回错误:(401) Unauthorized on Mac OS only - EWS. The request failed. The remote server returned an error: (401) Unauthorized on Mac OS only C#/ Restsharp:HTTP错误417期望失败 - C#/Restsharp: HTTP Error 417 Expectation failed 远程服务器返回错误:(412) Precondition Failed - The remote server returned an error: (412) Precondition Failed 请求失败,HTTP状态为417:期望失败 - 使用Web服务 - The request failed with HTTP status 417: Expectation Failed - Using Web Services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM