Logo HeaderGraphic
"... A Yankee in the Land of The Long White Cloud, Aotearoa ..."

WCF, Simple HTTP, Unhelpful Errors: EndpointNotFoundException, ProtocolException 

As you may know from these entries here and here, I’m working with WCF and hating its configuration, I love WCF, administering it on the other hand… .  And for the past two days, I totally wasted my time and my client’s time because of the poor ability of WCF to assist you with figuring out there is something wrong with your configuration file (and not your code / service).  I’m actually now going to have to work on my weekend at no charge to make it up to the client, because they shouldn’t have to pay for this mistake.  Working for free makes me hot under the collar, but fair is fair.

So let me walk you thru the problem.  In the process of reconfiguring the code I suddenly encountered this error when I tried to call my WCF proxy EndpointNotFoundException with an inner html error of 404 Not Found. 

image

image

So here is the edited version of the error output it tells you to check out

System.ServiceModel.EndpointNotFoundException was unhandled by user code
  Message="There was no endpoint listening at http://localhost/RinconServicesController/Synchronization.svc that could accept the message. ... See InnerException, if present, for more details."
   InnerException: System.Net.WebException
       Message="The remote server returned an error: (404) Not Found."
       InnerException: 

and Click below if you want to see the entire raw exception output.

System.ServiceModel.EndpointNotFoundException was unhandled by user code
  Message="There was no endpoint listening at http://localhost/RinconServicesController/Synchronization.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."
  Source="mscorlib"
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Send(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at IControllerSynchronization.SynchronizeSheets(Guid synchronizationUid, Guid satelliteNodeUid, BulkSheetDataPackage package)
       at ControllerSynchronizationClient.SynchronizeSheets(Guid synchronizationUid, Guid satelliteNodeUid, BulkSheetDataPackage package) in C:\src\Rincon\DataExportImport\Services\Satellite\ControllerSynchronizationClient.cs:line 178
       at Bst.Rincon.DataExportImport.Services.Satellite.SatelliteSynchronization.SendSheetsToController(Guid controllerNodeUid) in C:\src\Rincon\DataExportImport\Services\Satellite\SatelliteSynchronization.cs:line 421
       at Bst.Rincon.DataExportImport.Services.Satellite.SatelliteSynchronization.SheetSynchronizationRequested(Guid controllerNodeUid) in C:\src\Rincon\DataExportImport\Services\Satellite\SatelliteSynchronization.cs:line 655
       at SyncInvokeSheetSynchronizationRequested(Object , Object[] , Object[] )
       at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
       at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
  InnerException: System.Net.WebException
       Message="The remote server returned an error: (404) Not Found."
       Source="System"
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       InnerException: 

Wow, my service is not found, so for a DAY I try to figure out why my service is not found on this one particular call, because you see to make it even more nonsensical, I have 15 other wcf calls that work fine from this client to the server, just not THIS call.  What could possible make my service “disappear” on just this one call.  Turns out, it doesn’t disappear.  Oh no, its there all right and it’s working fine, the problem isn’t that the service isn’t working, its that I’m trying to send too much data.  I discover this by building up a new call from scratch that bit by bit, I make it duplicate the call that is failing, adding a little more information as I go along, and it works, and it works, until suddenly when I try to push down the full data package I get the same error. 

A little more testing shows me that its the size of the amount of data I’m trying to send.  Mind you now that I go back and re-read that error, notice it didn’t say there was no endpoint listening (full stop), no it said there was no endpoint listening that could accept the message.  Wow, so I need to increase the buffer sizes on the receiving end.  So

<basicHttpBinding>
 <binding name="SynchronizationBinding" maxBufferSize="65536" maxReceivedMessageSize="65536">
  <readerQuotas maxStringContentLength="65536" maxArrayLength="65536" />
 </binding>
</basicHttpBinding>
becomes
<basicHttpBinding>
 <binding name="SynchronizationBinding" maxBufferSize="2000000" maxReceivedMessageSize="2000000">
  <readerQuotas maxStringContentLength="2000000" maxArrayLength="2000000" />
 </binding>
</basicHttpBinding>
and now the error I get is

image 

Now that one at least tells me something that I need to fix ( and since I’ve encountered it before I know what to do here, mind you, exactly how to determine how to fix that can be its own headache, as I detailed in this post), So off I go to fix it and then I get this error…

image

And here is the abbreviated error message:

System.ServiceModel.ProtocolException was unhandled by user code
  Message="The remote server returned an unexpected response: (400) Bad Request."
  InnerException: System.Net.WebException
       Message="The remote server returned an error: (400) Bad Request."
       InnerException: 

Click here if you want to see the whole raw thing

System.ServiceModel.ProtocolException was unhandled by user code
  Message="The remote server returned an unexpected response: (400) Bad Request."
  Source="mscorlib"
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Send(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at IControllerSynchronization.SynchronizeSheets(Guid synchronizationUid, Guid satelliteNodeUid, BulkSheetDataPackage package)
       at ControllerSynchronizationClient.SynchronizeSheets(Guid synchronizationUid, Guid satelliteNodeUid, BulkSheetDataPackage package) in C:\src\Rincon\DataExportImport\Services\Satellite\ControllerSynchronizationClient.cs:line 178
       at Bst.Rincon.DataExportImport.Services.Satellite.SatelliteSynchronization.SendSheetsToController(Guid controllerNodeUid) in C:\src\Rincon\DataExportImport\Services\Satellite\SatelliteSynchronization.cs:line 421
       at Bst.Rincon.DataExportImport.Services.Satellite.SatelliteSynchronization.SheetSynchronizationRequested(Guid controllerNodeUid) in C:\src\Rincon\DataExportImport\Services\Satellite\SatelliteSynchronization.cs:line 655
       at SyncInvokeSheetSynchronizationRequested(Object , Object[] , Object[] )
       at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
       at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
  InnerException: System.Net.WebException
       Message="The remote server returned an error: (400) Bad Request."
       Source="System"
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       InnerException: 

So this time, I’m getting a little smarter (and besides I still have my test service call I was spooling up to see at what point things broke).  After 3 hours of attempting to figure out what is corrupting my request, I decide I’m not going to trust this error to really mean what it seems to mean.  Perhaps this is also a misleading error.  Let’s assume for the moment that it’s a size issue again (I know, if it was a size issue, I should seem the same error as before, but this seems to be a different error), using my test service let’s slowly increase the message in chunks, and what do you know, I’m correct, it’s all about size again ( let’s just let that line lay there shall we?).

So basicHttpBinding entry is modified one more time from this

<basicHttpBinding>
 <binding name="SynchronizationBinding" maxBufferSize="2000000" maxReceivedMessageSize="2000000">
  <readerQuotas maxStringContentLength="2000000" maxArrayLength="2000000" />
 </binding>
</basicHttpBinding>
modified to this
<basicHttpBinding>
    <binding name="SynchronizationBinding" maxBufferSize="2147483647"
     maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
         maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
</basicHttpBinding>

And finally it works.

Now to be fair, once I knew it was all about size, I could have gone and looked at the size of the package using fiddler tools and seen that it was too big… but look at my solution, to just make everything as big as is allowed by the type, and in the end, its still possible that the user will try to send thru something that may be too big in some way for one of these parameters.  How do I tell which one is the problem remotely for the client, so they can take actions to fix it?

With an error like (400) Bad Request, we are in a world of hurt when it comes to supporting the end-user thru automated tools.  I suspect that MSMQ may be our only solution and we will have to leave the Web Service calls behind.

Technorati Tags:
Digg This
 
Posted on 5-Apr-09 by Matthew C. Hintzen
Bookmark this post with:        
Tags: