Thursday, October 27

WCF errors: simple jargon-free problem and solution approach

There are lots of big terms in internet posts about WCF but it is actually a very simple concept once you can achieve an understanding of it's fundamental ideology. Getting to the core of the methodology can be very daunting for beginners. I just thought I'd make a growing journal of errors I encountered in my first WCF implementations (which I have just discovered nicely noted in one of my old work journals. Hope these will help asomeone out there at some point....

P: You get the error The message could not be processed because the action '' is invalid or unrecognized” when trying to implement wshttpbinding configuraiton with establishsecuritycontext set to false

S: Most likely caused because your ser4vice reference did not update the establishSecurityContext attribute of the Message element in the binding configuration. This is a VS bug
In your client configuraiton (app.config) manually add the establishSecurityContext="true" attribute to the message node of the security element for the relevant binding. e'g
<message clientCredentialType="Windows" negotiateServiceCredential="true"establishSecurityContext="true" algorithmSuite="Default" />

P: when using the svcutil tool to generate metadata from a wsdl, you get an error of the type "the t option requires that a value be specified"
S: You have most likely added a space between the /t and :metadata in the svcutil.exe command syntax. Remove the space so the command is of the form 'svcutil.exe /t:metadata http:/getme/data.wsdl (where http/getme/data.wsdl is the url of the service wsdl). See this link for more information  on the tool

P: After making changes to a BizTalk IIS-hosted WCF service, when trying to use the service from a client you get constant timeouts. On checking events, you find the BizTalk error "The Messaging Engine received an error from transport adapter "WCF-CustomIsolated" when notifying the adapter with the BatchComplete event. Reason "Attempted to access an unloaded AppDomain."."
S: Reset IIS

P: When publishing your BizTalk application as a wcf service, you get an error of the sort "The Messaging Engine failed to register an adapter.... Details: "Registering multiple adapter types within the same process is not a supported scenario. For e.g. HTTP and SOAP receive adapters cannot co-exist in the same process "
S: You need to create a new applicaiton pool for the service. An isolated host instance can run only one adapter. If you configure the receive handlers of HTTP and SOAP adapters with the same isolated host, you must create two application pools, one application pool for each adapter

P: 'An existing connection was forcibly closed by the remote host' error when using a wcf service - more often than not occurs with large files…”
S: The first port of call for this is to amend your web.config file in the wcf service and increase the maxBufferPoolSize and maxReceivedMessageSize in your binding configuration. (If connecting from BizTalk, you should also increase these values in your port binding configuration from the default .Net value of 65, 356 bytes. This is not the probem in this case anyway, as this would have given you a different error). Setting the attribute transferMode="Streamed" in this section also helps to minimize memory impact

In my case, I was using a WCf service as a wrapper for extra protection to modify and send an xml file to an old-fashioned xmlhttpRequest web page hosted in PeopleSoft. the configuration above (which I had already done when building the wcf service anyway) did not solve the problem. If changing those settings does not work, add a httpruntime config setting in the System.Web section of your web.config file as shown below, using values that work more with your expected message size etc:

<httpRuntime executionTimeout="90" maxRequestLength="200000000" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>

P: Trying to load a WCF web service and getting error similar to “the runtime is built with a newer runtime…”
S: Browse to Application Pool in IIS (double click) and change the runtime to the same runtime as the one specified in your web service web.config file’s target framework declaration
(e.g. targetFramework="4.0") – This solution may lead to the next error

P: When trying to browse your web service svc file in a IIS hosting environment, you get the error HTTP Error 500.21 - Internal Server Error
Handler "svc-Integrated" has a bad module "ManagedPipelineHandler" in its module list
S: IIS is not properly registered with visual studio – Open visual studio command prompt (run as administrator if using Vista) and type aspnet_regiis.exe –i

P: trying to browse your web service svc file in a IIS hosting environment, you get the error ‘The protocol 'net.pipe' is not supported’
S: IIS 5 and 6 only support http-based bindings. Remove any bindings that do not use one of the http-based protocols to remove this error

P: wcftestclient command runs your client successfully, but once in IIS environment, you get the error ‘Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.’
S: You need to add a metadata exchange (mex) endpoint to your service config file:
Something like:
<service name="NewService.Service1" behaviorConfiguration="metadataBehavior"> 
binding="customBinding" bindingConfiguration="jsonpBinding"  

P: you want to create a wcf service but you don't want the default namespace on your generated schemas
S: You need to add a namespace attribute to your ServiceContract declaration:
Something like:
[ServiceContract( Namespace = "" )]


  1. Thanks. I had the:
    "The message could not be processed because the action '' is invalid or unrecognized" problem and this post quickly gave me the "Duh, yes of course" I needed to get to the bottom of why. I was testing some client code that was pulled from a repository where the server web.config (IIS hosted WCF services) that it was targeting was not matching with the security context.

  2. Glad to have been of help :O)

  3. Hi,

    Got this exception:
    System.ServiceModel.Security.MessageSecurityException: An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail. ---> System.ServiceModel.FaultException: The message could not be processed because the action 'http://serviceurk/ITaskMgmtService/GetIncident' is invalid or unrecognized.

    Don't really know what the problem is... this config works for a service that is hosted in serv A, but not in servB (same config...) just editing the address... Do you know what the problem is?
    And got this in web.config

    1. Hi, I know you said the same config works on one server, but are you parameterizing your endpoints in the config? This exception suggests an issue with the soap action specified in your request. Check the URL being called on both servers, and if they are the same, subsequently, the soap action of the request on the server that works and make sure it tallies exactly with the failing one