Click here to Skip to main content
15,883,841 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I'm developing a WCF service and the QA department is using Soap UI to invoke methods and send test data. They have reported an error when using an ampersand character in a text field of the request.

Offers.API.Infrastructure.Handlers.ServiceErrorHandler.ProvideFault|notauth::

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://namesapce.net/api/offers:model. 

The InnerException message was 'There was an error deserializing the object of type Offers.TransportModel.OfferModel. 

Unexpected end of file. Following elements are not closed: Description, OfferDescriptionModel, Conditions, model, CreateOffer, Body, Envelope. Line 353, position 20.'. 


The request they are sending from SOAP UI looks something like this...

XML
<off:Conditions>
    <off:OfferDescriptionModel>
      <off:CultureFormat></off:CultureFormat>
      <off:CultureInvariantId>0</off:CultureInvariantId>
      <off:Description>QA API & Added Value 15</off:Description>
      <off:IsInvariant>true</off:IsInvariant>
   </off:OfferDescriptionModel>
</off:Conditions>


* If they properly encode the ampersand in SOAP UI, then no error occurs.
* When calling the service from a proxy generated by svcutil, characters are properly encoded and no error occurs.

My Issue:
The error returned isn't the greatest - I'd prefer it to handle a bit more gracefully.

I cannot guarantee how the clients consuming the service are going to be generating their requests - so there's nothing I can do in terms of setting encoding etc on the request. I can only handle in the service.

Question(s):

* Is there anything I can do to help WCF when deserializing content that may not be properly encoded? Is there a simple service setting I'm missing?

If WCF could automagically handle all encoding service side for me, great.

Otherwise, any other options appreciated.


Thanks
Posted
Comments
fjdiewornncalwe 15-Oct-12 17:29pm    
I'd imagine that your only solution would be to wrap that deserialization in a try-catch so that you can gracefully send the "Your data is screwed" message back to the consumer.
Dylan Morley 16-Oct-12 3:51am    
Unfortunately, I don't have the chance to do this - it's thrown by the runtime before it even hits any of my code. I guess I could create my own deserializer and manually handle, but was hoping for a one liner config change or something along those lines :)
n.podbielski 15-Oct-12 18:30pm    
And what if you replace deserializer class and just replace method that throws this error and if you encounter data like this send another message to satisfy inhuman needs of QA?

In first answer linq there is interesting link that might be usefull:

http://stackoverflow.com/questions/1224925/wcf-deserialization-issue
Dylan Morley 16-Oct-12 4:07am    
I was trying to avoid having to change the deserializer from the default - might cause more problems than it solves.

I created an implementation of IErrorHandler (ServiceErrorHandler), so I might just trap for the Exception type and return something a bit more useful to the client.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900