2013-12-13 18 views
27

Sto provando a creare un servizio di applicazione WCF, utilizzando FW4.0. Il mio servizio funziona correttamente durante il trasferimento dell'oggetto EntiryFramework tra server e client. Ma sto avendo problemi a passare l'oggetto EF da Client a Server.Il server remoto ha restituito una risposta imprevista: (413) Entità richiesta troppo grande.

Qui qualche dettaglio circa il mio ambiente: - Il servizio è in esecuzione in modalità di debug a livello locale su IIS - Io corro tutto questo sul mio Windows 7 - sto usando Visual Studio 2010 su FW4.0

sto cercando di inviare un oggetto (tblClient) per server per salvare il record, ma continuare ad avere l'errore (413) Entità richiesta troppo grande. Qui lo stack completo:

System.ServiceModel.ProtocolException occurred 
     HResult=-2146233087 
     Message=The remote server returned an unexpected response: (413) Request Entity Too Large. 
     Source=mscorlib 
     StackTrace: 
     Server stack trace: 
      at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding) 
      at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
      at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 
      at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 
      at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
      at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
      at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 
     Exception rethrown at [0]: 
      at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
      at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
      at ClientApp.ServiceReference1.IService.SaveClient(tblClient client) 
      at ClientApp.ServiceReference1.ServiceClient.SaveClient(tblClient client) in C:\dufh\WPF Project\ClientApp\Service References\ServiceReference1\Reference.vb:line 2383 
      at ClientApp.ViewModel.ClientViewModel.SaveClient() in C:\dufh\WPF Project\ClientApp\ViewModel\ClientViewModel.vb:line 48 
     InnerException: System.Net.WebException 
      HResult=-2146233079 
      Message=The remote server returned an error: (413) Request Entity Too Large. 
      Source=System 
      StackTrace: 
       at System.Net.HttpWebRequest.GetResponse() 
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
      InnerException: 

Ho fare qualche ricerca e puntano tutti alla MaxBufferSize e/o maxBufferPoolSize e/o una strega MaxReceivedMessageSize non è abbastanza grande nella configurazione client app.config. Quindi li ho analizzati al valore massimo: maxBufferSize = "2147483647" maxBufferPoolSize = "2147483647" maxReceivedMessageSize = "2147483647" Tuttavia, l'errore rimane.

Qui il mio client completo app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.diagnostics> 
    <sources> 
     <!-- This section defines the logging configuration for My.Application.Log --> 
     <source name="DefaultSource" switchName="DefaultSwitch"> 
     <listeners> 
      <add name="FileLog"/> 
      <!-- Uncomment the below section to write to the Application Event Log --> 
      <!--<add name="EventLog"/>--> 
     </listeners> 
     </source> 
    </sources> 
    <switches> 
     <add name="DefaultSwitch" value="Information" /> 
    </switches> 
    <sharedListeners> 
     <add name="FileLog" 
      type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 
      initializeData="FileLogWriter"/> 
     <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --> 
     <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="MVVM Sampling"/> 
    </sharedListeners> 
    </system.diagnostics> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:7803/Service1.svc" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService" 
      name="BasicHttpBinding_IService" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

e il servizio WCF Web.Config completo Web.Config

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 

    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"> 
      <readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 


    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <connectionStrings> 
    <add name="MaitreEntities" connectionString="metadata=res://*/Schemat.csdl|res://*/Schemat.ssdl|res://*/Schemat.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=INFOFILE2\SQL2008R2;initial catalog=0001ConneryFerland;user id=sa;password=kermit80;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
</configuration> 


Any help would be very welcome :-) 

risposta

58

Per la cronaca

penso di aver capito. Il Web.Config dal servizio non ha le informazioni di rilegatura. Ho inserito queste informazioni e voilà!

<bindings> 
     <basicHttpBinding> 
     <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text"> 
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
     </basicHttpBinding> 
</bindings> 

notare qui che l'associazione non ha avuto un nome specificato.

+4

Grazie! "web.config dal servizio" significa: "web.config sul server". –

+1

Grazie. Mi ci sono volute un paio d'ore per cercare di trovare quale legame mancasse ed era il collegamento web.config lato servizio senza un nome come nel tuo esempio. –

+0

Grazie! Nel mio caso ho avuto un servizio web che mancava il nodo - grazie Hugo! –

11

Non è un endpoint esplicito (cioè quello definito nel file di configurazione) per il tuo servizio, quindi la configurazione di bind dichiarata ("BasicHttpBinding_IService") non viene utilizzata. WCF fornisce un endpoint predefinito insieme a un'associazione predefinita (basicHttpBinding a meno che non si esegua l'overroding nella sezione protocolMapping del file di configurazione).

ci sono due modi per risolvere questo nel file di configurazione del vostro servizio:

È possibile effettuare la configurazione "BasicHttpBinding_IService" il default rimuovendo l'attributo name:

<binding maxBufferPoolSize="2147483647"..... 

Oppure si definiscono un endpoint in modo esplicito nella configurazione e assegnare la configurazione vincolante all'attributo bindingConfiguration dell'endpoint.

<services> 
    <endpoint address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IService"  
       contract="ServiceReference1.IService" /> 
</services> 
+0

Grazie per il tuo aiuto, Tim, ma l'errore permane. Metterò da parte il mio servizio WCF per un po '. E lasciate cuocere per un po '... – Hugo

0

Se si crea l'associazione personalizzata ad es.MybasicBinding,

<basicHttpBinding> 
     <binding name="MybasicBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" 
       maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" > 
      <readerQuotas maxDepth="32" maxBytesPerRead="200000000" 
      maxArrayLength="200000000" maxStringContentLength="200000000" /> 
     </binding> 
    </basicHttpBinding> 

per evitare l'errore 413, Non foreget per specificare il bindingConfiguration = "MybasicBinding" per servizio endpoint come,

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MybasicBinding" contract="WCFService.IService" /> 
1

Un altro modo per risolvere questo problema e hanno un guardare meglio il file web.config, è modificare il file web.config con "Microsoft Service Configuration Editor" (C: \ Programmi (x86) \ Microsoft SDK \ Windows \ v8.1A \ bin \ NETFX 4.5.1 Strumenti \ SvcConfigEditor.exe)

Problemi correlati