2012-10-03 80 views
6

estoy escribiendo la aplicación Windows 8 (en Visiual Studio 2012) que utiliza mi servicio wcf. Funciona bien cuando intento en mi casa, por lo que se puede conectar al wcf. Pero cuando he intentado en mi oficina, no se puede conectar a WCF y devuelve error:"El servidor remoto devolvió un error: (417) Expectation Failed."

The remote server returned an error: (417) Expectation Failed.

Creo que es causa de cortafuegos en la red de oficinas .. Googled demasiado, intentó muchas embargo el problema sigue aquí .

no funciona porque .Net Framework 4.5 no tiene ServicePointManager Clase MSDN, pero dice que no es ServicePointManager en .Net 4.5 .. http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue.aspx

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

No se puede probar esto para escribir en web.config o app.config porque la aplicación win8 no tiene estos archivos ...

Algunas personas escribieron el código anterior en el archivo devenv.exe.config de VS 2012. Lo intenté pero no cambió nada.

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

+2

He visto este error antes cuando mis llamadas a servicios web estaban siendo bloqueadas por un proxy – lockstock

Respuesta

1

Bueno, usted ha escrito la pregunta here y Can Bilgin dio una respuesta. Lo publico aquí para aquellos que tienen el problema que tú.

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):

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(); 
0

Para referencia, el siguiente es un ejemplo completo de la utilización de WebClient para enviar una solicitud JSON a un servicio web REST. Establece el indicador Expect100Continue en false, incluye la autenticación de proxy utilizando las credenciales predeterminadas si es necesario, y captura códigos de respuesta que no son 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; } 
} 
0

Aunque la adición de esta línea
() como un ajuste a la configuración puede solucionar el error inicial es probable que aún así obtener (504) Pasarela interrumpida si la configuración del proxy no son lo que permite utilizar la correcta abrir el puerto abierto a su en el servidor de destino. Para agregar una excepción de proxy para el servidor al que está enviando, agréguelo a través de Internet Explorer como una exclusión de proxy en la pestaña de conexiones -> Configuración de LAN -> Avanzado. Espero que puedas conectarte entonces.

Cuestiones relacionadas