Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Silverlight 2 WCF Service returns 404 with upload of image
6 replies. Latest Post by lepipele on May 4, 2009.
(1)
bradtpm
Member
54 points
15 Posts
03-25-2008 5:48 PM |
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.
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 Serviceprivate 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);}
// Upload an Image to the WCF Serviceprivate 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
03-25-2008 11:42 PM |
I have done another test. It seems to be the parameter size that I pass to the Service.
I made a test Service:
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.
Binding.MaxBufferSize = 2000000;
Binding.MaxReceivedMessageSize = 2000000;
DesignerClient =
Server:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="ServicesBinding" maxReceivedMessageSize="2000000"> <readerQuotas maxArrayLength="2000000"/> </binding> </basicHttpBinding> </bindings>
<
03-26-2008 12:12 PM |
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
Participant
1163 points
469 Posts
09-04-2008 1:45 PM |
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
2 points
1 Posts
11-24-2008 12:27 PM |
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
4 points
2 Posts
03-09-2009 4:20 PM |
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
44 points
22 Posts
05-04-2009 7:31 PM |
Thanks for great topic