Click here to Skip to main content
15,896,489 members

WCF Deserialization Issue - XML Control Characters

Dylan Morley asked:

Open original thread
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
Tags: .NET (.NET4), WCF

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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