2011-04-25 14 views
5

He estado intentando buscar este error, pero hasta ahora no tuve suerte.cargando xml grande al servicio WCF REST -> 400 Solicitud incorrecta

Así que tener un servicio en mi cliente con este web.config

<system.serviceModel> 
<serviceHostingEnvironment> 
    <baseAddressPrefixFilters> 
    <add prefix="http://www.mywebsite.com/"/> 
    </baseAddressPrefixFilters> 
</serviceHostingEnvironment> 
<services> 
    <service behaviorConfiguration="ServiceBehavior" name="UploadService"> 
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" 
     contract="IUploadService"> 
     <identity> 
     <dns value="http://www.mywebsites.com/" /> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="ServiceBehavior" maxReceivedMessageSize="4194304"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

y en el cliente tengo esta configuración

<system.serviceModel> 
<bindings> 
    <wsHttpBinding> 
    <binding name="WSHttpBinding_IUploadService" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" 
     bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferPoolSize="524288" maxReceivedMessageSize="4194304" 
     messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
     allowCookies="false"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <reliableSession ordered="true" inactivityTimeout="00:30:00" 
     enabled="false" /> 
     <security mode="Message"> 
     <transport clientCredentialType="Windows" proxyCredentialType="None" 
      realm=""> 
      <extendedProtectionPolicy policyEnforcement="Never" /> 
     </transport> 
     <message clientCredentialType="Windows" negotiateServiceCredential="true" 
      algorithmSuite="Default" establishSecurityContext="true" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://www.mywebsite.com/UploadService.svc" 
    binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService" 
    name="WSHttpBinding_IUploadService"> 
    <identity> 
     <dns value="http://www.mywebsite.com/" /> 
    </identity> 
    </endpoint> 
</client> 

y estoy cargando los archivos de esta manera: -

 using (Stream stream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read)) 
     { 
      try 
      { 
       using (UploadServiceClient upc = new UploadServiceClient()) 
       { 
        upc.UploadFile(stream); 
       } 

      } 
      catch (Exception exc) 
      { 

      } 
     } 

para archivos pequeños funciona bien, pero para grandes archivos XML, esto falla con 400 Bad Request. ¿Qué puedo hacer para cambiar estas configuraciones y obtener un archivo XML grande para transferir?

Gracias por su ayuda y tiempo

app.config cliente actualizados

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="basicHttpBinding_IUploadService" receiveTimeout="00:20:00" 
     bypassProxyOnLocal="true" maxBufferSize="4194304" maxReceivedMessageSize="4194304" 
     messageEncoding="Mtom" transferMode="Streamed"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security> 
     <transport> 
      <extendedProtectionPolicy policyEnforcement="Never" /> 
     </transport> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://www.mywebsite.com/UploadService.svc" 
    binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService" 
    name="basicHttpBinding_IUploadService"> 
    <identity> 
     <dns value="http://www.mywebsite.com/" /> 
    </identity> 
    </endpoint> 
</client> 

Respuesta

2

Usted debe ver si el servicio tiene el mismo maxReceivedMessageSize = "4194304" como el cliente y si el XML es de hecho más pequeño que el límite de 4,194,304 bytes establecido. WCF se establece de forma predeterminada en maxReceivedMessageSize de 64K.

ACTUALIZACIÓN:

Noté su configuración muestra el cliente está configurado para basicHttpBinding pero la configuración sólo se muestra una wsHttpBinding. La configuración de wsHttpBinding sería ignorada por WCF ya que no pertenece a basicHttpBinding. Si el archivo de configuración del cliente no tiene un elemento basicHttpBinding, en .NET 4 se está utilizando uno predeterminado. Si esto es cierto, se encontrará con el límite de 64 KB descrito anteriormente.

+0

sí ambos son 4194K y el mensaje es más pequeño que 4G – Johann

+0

Cambié el archivo app.config en el lado del cliente y agregué un BásicoHTTPBinding, sin embargo, sigo recibiendo el mismo error – Johann

+0

Por favor intente reemplazar el elemento basicHttpBinding (si hay uno) en el servicio web.config con el utilizado en el archivo de configuración del cliente de su actualización que se muestra arriba. Ya sea que funcione o no, sabremos que tanto el cliente como el servicio están usando la misma configuración. Si actualmente no tiene un elemento basicHttpBinding en el archivo web.config, este cambio debería solucionar el problema. –

Cuestiones relacionadas