Skip to main content

Microsoft Silverlight

Answered Question Silverlight 2 WCF Service returns 404 with upload of imageRSS Feed

(1)

bradtpm
bradtpm

Member

Member

54 points

15 Posts

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
bradtpm

Member

Member

54 points

15 Posts

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
bradtpm

Member

Member

54 points

15 Posts

Answered Question

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>

brauliod
brauliod

Participant

Participant

1163 points

469 Posts

Silverlight MVP

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.dbschemaeditor.com
    Free Silverlight Based Database Schema Editor
/// ---------------------------------

fallen888
fallen888

Member

Member

2 points

1 Posts

Re: Silverlight 2 WCF Service returns 404 with upload of image

I ran into the same exact issue and eventually figured out the problem, but the biggest question is... How do we programmatically handle the appropriate WCF messages (and not these vague and very unhelpful ones)?

rdlecler
rdlecler

Member

Member

4 points

2 Posts

Re: Silverlight 2 WCF Service returns 404 with upload of image

Billiant! I have been stuck on this problem for the past 20 hours. I was modifying some LINQ + SQL + WCF + Silverlight + DataGrid code I found on the Swiss MSDN Team Blog and I was getting a very unhelpful error when uploading a new image (which happened to be a 1KB larger):

"System.ServiceModel.CommunicationException was unhandled by user code: The remote server returned an error: NotFound"

I first thought it wasn't updating the write, and then I thought it might have been a clientaccesspolicy.xml issue. Eventually I came across a IE plugin for logging http errors (link), and found out that I was getting a 500 error caused by an insufficient quota for XmlDictionaryReaderQuota. The code I found had set the quota in the code, but not in the XML file. I'm posting the original error message below in case anyone is doing a search. One last thing, if you use the code from the Swiss Team Blog, there is also a bug with their "save customer data" button -- apparently the call to "LinqHelper.GetModifiedsObectsOnly()" unloads the datasource on the datagrid, so you need to reload the datasource in the "client_SaveCustomersCompleted()" call back method. Otherwise all the non-update entries will be pointing to null values in the code, but are still visible in the grid.

//Original error message:

System.ServiceModel.CommunicationException was unhandled by user code
  Message="The remote server returned an error: NotFound"
  StackTrace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       at SilverlightApplication4.ServiceReference2.Service2Client.Service2ClientChannel.EndSaveVectors(IAsyncResult result)
       at SilverlightApplication4.ServiceReference2.Service2Client.SilverlightApplication4.ServiceReference2.IService2.EndSaveVectors(IAsyncResult result)
       at SilverlightApplication4.ServiceReference2.Service2Client.OnEndSaveVectors(IAsyncResult result)
       at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
  InnerException: System.Net.WebException
       Message="The remote server returned an error: NotFound"
       StackTrace:
            at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
            at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
       InnerException: System.Net.WebException
            Message="The remote server returned an error: NotFound"
            StackTrace:
                 at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
                 at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
                 at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
            InnerException:

 

 

 

lepipele
lepipele

Member

Member

44 points

22 Posts

Re: Silverlight 2 WCF Service returns 404 with upload of image

 Thanks for great topic

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities