Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WCF .NET4
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...
 
<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 15-Oct-12 5:33am
Comments
Marcus Kramer at 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 at 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 at 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 at 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)

  Print Answers RSS
0 DamithSL 320
1 OriginalGriff 195
2 Afzaal Ahmad Zeeshan 154
3 BillWoodruff 135
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,994
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100