Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Silverlight 2 WCF Service returns 404 with upload of image RSS

6 replies

Last post May 04, 2009 11:31 PM by lepipele

(1)
  • bradtpm

    bradtpm

    Member

    54 Points

    15 Posts

    Silverlight 2 WCF Service returns 404 with upload of image

    Mar 25, 2008 09:48 PM | LINK

    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

    54 Points

    15 Posts

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

    Mar 26, 2008 03:42 AM | LINK

    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

    54 Points

    15 Posts

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

    Mar 26, 2008 04:12 PM | LINK

    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

    Contributor

    2448 Points

    744 Posts

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

    Sep 04, 2008 05:45 PM | LINK

    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?

  • fallen888

    fallen888

    Member

    2 Points

    1 Post

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

    Nov 24, 2008 04:27 PM | LINK

    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

    4 Points

    4 Posts

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

    Mar 09, 2009 08:20 PM | LINK

    I had a similar problem. I was modifying some LINQ + SQL + WCF + Silverlight + DataGrid code I on 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"

    The code I found had set the quota in the code for the client, but not in Web.config for the service. I'm posting the original error message below in case anyone is doing a search.

    While I am here, 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

    44 Points

    25 Posts

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

    May 04, 2009 11:31 PM | LINK

     Thanks for great topic