5

I have WCF service through which I am adding data in DB. It works fine, but when I try to send large byte[] it returns "remote server returned an error: NotFound".

web.config

    <?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="JabsBaseConnectionString" connectionString="Data Source=TAHASAGHIR-PC\SQLEXPRESS;Initial Catalog=JabsBase;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true"/>
  </system.web>
  <system.serviceModel>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="SendLargeChat"
                 allowCookies="false"
                 bypassProxyOnLocal="false" 
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647"
                 closeTimeout="10:00:00"
                 openTimeout="10:00:00"
                 receiveTimeout="10:00:00"
                 sendTimeout="10:00:00"
                 transferMode="Streamed">
          <readerQuotas 
            maxArrayLength="2147483647"
            maxBytesPerRead="2147483647"
            maxDepth="2147483647"
            maxNameTableCharCount="2147483647"
            maxStringContentLength="2147483647" />
        </binding>
      </basicHttpBinding>      
    </bindings>
    <services>
      <service name="Prototype.SendChatService" behaviorConfiguration="Prototype.SendChatServiceBehavior">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="SendLargeChat" contract="Prototype.SendChatService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>      
    </services>    
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="Prototype.SendChatServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

ServiceReferences.ClientConfig

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>        
        <binding name="BasicHttpBinding_ISendChatService" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>      
    </bindings>
    <client>      
      <endpoint address="http://localhost:53756/PrototypeSite/SendChatService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISendChatService"
        contract="SendChatService.ISendChatService" name="BasicHttpBinding_ISendChatService" />
    </client>
  </system.serviceModel>
</configuration>

Request POST http://localhost:53756/PrototypeSite/SendChatService.svc HTTP/1.1 Host: localhost:53756 Connection: keep-alive Referer: http://localhost:53756/PrototypeSite/ClientBin/Prototype.xap Content-Length: 1348176 soapaction: "http://tempuri.org/ISendChatService/addMsg" content-type: text/xml; charset=utf-8 Accept: / User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Response HTTP/1.1 400 Bad Request Server: ASP.NET Development Server/10.0.0.0 Date: Thu, 26 May 2011 17:48:00 GMT X-AspNet-Version: 4.0.30319 Cache-Control: private Content-Length: 0 Connection: Close

6 Answers 6

2

The 404/Not Found is the error Silverlight reports for all server errors. If you want to know the actual error being returned from the server you can use something like Fiddler to view what is being sent and received, including the headers which contain the actual error code and error message returned by the server.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks David... I am editing my original post! Please check the request and response.
Bad Request could be a number of things: the xml sent is broken (you can check that in Fiddler, see if the request data can be viewed as XML), the contract used by the request is not the same as the server (unlikely if you've written both from the same WCF code), or the request violates a range check. Does the request exceed 64KB? It may be breaking the default MaxReceivedMessageSize limit set in your WCF service.
1

I think you should apply the same

<readerQuotas ...

On the client.

Comments

1

try to add a executionTimeout setting to your HTTPRuntime setting

<httpRuntime executionTimeout="110" maxRequestLength="..." />

Comments

1

In my experience, I was receiving an error because even though the service on the server was configured to receive a large amount of data, the http runtime wasn't. Make sure your httpRuntime has an appropriate maxRequestLength.

Comments

1

You can also turn on WCF logging for more information. Add the following to your web.config:

<system.diagnostics>
    <sources>
        <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true">
            <listeners>
                <add name="traceListener"
                     type="System.Diagnostics.XmlWriterTraceListener"
                     initializeData= "c:\log\Traces.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

Comments

0

SORRY MY ANSWER IS WRONG!! IGNORE IT

I will delete it in a few hours, just allowing people with comments to see it.

Do not send byte arrays in SOAP.

Each byte will be transferred as <byte>128</byte> or similar which means it will take on average 10 times more.

Use base64 string instead - so define your property as a string and populate it as base64 string.

4 Comments

Aliostad, thanks for your quick response! Can you please give the details of process, how to convert byte array to base64 string and vice versa?
wow. That's really something useful to know. Have you got a reference that explains this?
That doesn't sound right... I'm fairly sure that byte[] gets encoded as a Base64 string by the serializer... e.g. webservices20.blogspot.com/2010/10/…
Sorry for misguiding... see my comments. Once learns something everyday

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.