Page view counter
Silverlight 2 WCF Service returns 404 with upload of image
Last post 09-04-2008 1:45 PM by brauliod. 3 replies.
Sort Posts:
03-25-2008 5:48 PM
Silverlight 2 WCF Service returns 404 with upload of image

I can send an Image byte array that is less than 16 KB to my WCF Service. If I send anything bigger than that I get the following error:

An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code

Additional information: The remote server returned an unexpected response: (404) Not Found.

This error makes no sense as the only thing that I changed was the image. I have tested this with other files and receive the same thing. I have also set the Max Buffer size to 20000000. Anyone know what the problem could be?

I have not set the max received message on the WCF Service Web.Config file. Do I need to change that? This is only a guess as the error message makes no sense.

 Here's some code:

            // WCF
            System.ServiceModel.BasicHttpBinding Binding = new BasicHttpBinding(BasicHttpSecurityMode.None);

            Binding.MaxBufferSize = 200000000;
            Binding.MaxReceivedMessageSize = 200000000;
           
            EndpointAddress Address = new EndpointAddress("http://localhost/WCFService/Designer.svc");

            public DesignerServiceReference.DesignerClient DesignerClient = null;
            DesignerClient = new DesignerServiceReference.DesignerClient(Binding, Address);

// Upload an Image to the WCF Service
private void AddImageUserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    // Send
    Stream Stream = (System.IO.Stream)ImageAdd.OpenFileDialog.SelectedFile.OpenRead();

    byte[] Buffer = new byte[Stream.Length];
    Stream.Read(Buffer, 0, (int)Stream.Length);

    Stream.Dispose();
    Stream.Close();

    DesignerClient.SaveImageAsync(Buffer);
    DesignerClient.SaveImageCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(SaveImage_Completed);
}

The error occurs on the following line and the service code never gets executed:

            public void EndSaveImage(System.IAsyncResult result) {
                object[] _args = new object[0];
                base.EndInvoke("SaveImage", _args, result);
            }

Thanks,
brad

bradtpm

Loading...
Joined on 03-25-2008
Posts 15
03-25-2008 11:42 PM
Re: Silverlight 2 WCF Service returns 404 with upload of image

I have done another test. It seems to be the parameter size that I pass to the Service.

I made a test Service:

public void TestSize(string test)
{
    string blah = "";
}

I passed a 300 KB string to it and received a 404 error. I did some searching on this and found that it's a client error about EndPointNotFound.

If I pass "hello" the Service works. I have set the message size on the client and server yet I still get this error.

Client:

System.ServiceModel.BasicHttpBinding Binding = new BasicHttpBinding(BasicHttpSecurityMode.None);

Binding.MaxBufferSize = 2000000;

Binding.MaxReceivedMessageSize = 2000000;

EndpointAddress Address = new EndpointAddress("http://localhost/PrintStoreWCFService/Designer.svc");

DesignerClient = new DesignerServiceReference.DesignerClient(Binding, Address);

Server:

<system.serviceModel>
  <
bindings>
    <
basicHttpBinding>
      <
binding name="ServicesBinding" maxReceivedMessageSize="2000000">
      <
readerQuotas maxArrayLength="2000000"/>

    </
binding>
  </
basicHttpBinding>
</
bindings>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <
services>
    <
service behaviorConfiguration="WCFServices.DesignerBehavior" name="WCFServices.Designer"> 
      <
endpoint address="" binding="basicHttpBinding" contract="WCFServices.IDesigner">
      <
identity>
        <
dns value="localhost"/>
      </
identity>
     </
endpoint>
    </service>
</
services>

<behaviors>
  <
serviceBehaviors>
    <
behavior name="WCFServices.DesignerBehavior">
      <
serviceMetadata httpGetEnabled="true"/>
      <
serviceDebug includeExceptionDetailInFaults="true"/>
    </
behavior>
  </
serviceBehaviors>
 </
behaviors>
</
system.serviceModel>

 
bradtpm

Loading...
Joined on 03-25-2008
Posts 15
03-26-2008 12:12 PM
Marked as Answer
Re: Silverlight 2 WCF Service returns 404 with upload of image

I have found the problem. I downloaded the Windows SDK to get the SvcConfigurationManager utility and enable logging of the WCF messages.

In the message being returned I finally found an error I could actually understand instead of a 404.

The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'TestSize'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 8503

 It was as I thought, the server's incoming buffer needed to be increased. The problem though is I did set this in the Web.Config. What I didn't set was the "bindingConfiguration" property to tell the binding to use the new settings. Here's the correct configuration settings:

    <bindings>
      <basicHttpBinding>
        <binding name="ServicesBinding" maxReceivedMessageSize="2000000" maxBufferSize="2000000">
          <readerQuotas maxArrayLength="2000000" maxStringContentLength="2000000"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
   <service behaviorConfiguration="WCFServices.DesignerBehavior" name="WCFServices.Designer">
    <endpoint address="" bindingConfiguration="ServicesBinding" binding="basicHttpBinding" contract="WCFServices.IDesigner">
     <identity>
      <dns value="localhost"/>
     </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
   </service>
  </services>

bradtpm

Loading...
Joined on 03-25-2008
Posts 15
09-04-2008 1:45 PM
Re: Re: Silverlight 2 WCF Service returns 404 with upload of image

Excellent autoself responding post !!!!

 Many developers will find this issue sooner or later, and ... it's a bit hard to have advance skills on Silverlight, WCF, ADO .net entity Framework...

   This tip save my day :-), Are you planning to post it in a blog?

// ---------------------------------
    Braulio Diez

    http://www.tipsdotnet.com
// ---------------------------------

brauliod

Loading...
Joined on 06-04-2007
Malaga (Spain)
Posts 230
Microsoft Communities