c# - Deserializing an xml element in WCF with XML Declaration -


i have little wcf service has following signature:

string processmessage(xmlelement xmlsource); 

when request without xml declaration, webservice works fine, xml declaration added, crash.

the request works

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">     <soapenv:header/>     <soapenv:body>         <tem:processmessage>             <tem:xmlsource>                             <clipped>elements here</clipped>             </tem:xmlsource>         </tem:processmessage>     </soapenv:body> </soapenv:envelope> 

the request doesn't work

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">     <soapenv:header/>     <soapenv:body>         <tem:processmessage>             <tem:xmlsource>             <?xml version="1.0" encoding="utf-8"?>                                 <clipped>elements here</clipped>             </tem:xmlsource>         </tem:processmessage>     </soapenv:body> </soapenv:envelope> 

and crash:

<message>no characters can appear before xml declaration. line 7, position 14.</message>                      <stacktrace>at system.xml.xmlexceptionhelper.throwxmlexception(xmldictionaryreader reader, string res, string arg1, string arg2, string arg3)    @ system.xml.xmlutf8textreader.readdeclaration()    @ system.xml.xmlutf8textreader.read()    @ system.xml.xmlbasereader.movetocontent()    @ system.xml.serialization.xmlserializationreader.readxmlnode(boolean wrapped)    @ microsoft.xml.serialization.generatedassembly.xmlserializationreaderinbuwprocessingservice.read1_processmessage()    @ microsoft.xml.serialization.generatedassembly.arrayofobjectserializer.deserialize(xmlserializationreader reader)    @ system.xml.serialization.xmlserializer.deserialize(xmlreader xmlreader, string encodingstyle, xmldeserializationevents events)</stacktrace>                      <type>system.xml.xmlexception</type>                   </innerexception>                   <message>there error in xml document (7, 14).</message>                   <stacktrace>at system.xml.serialization.xmlserializer.deserialize(xmlreader xmlreader, string encodingstyle, xmldeserializationevents events)    @ system.xml.serialization.xmlserializer.deserialize(xmlreader xmlreader, string encodingstyle)    @ system.servicemodel.dispatcher.xmlserializeroperationformatter.deserializebody(xmldictionaryreader reader, messageversion version, xmlserializer serializer, messagepartdescription returnpart, messagepartdescriptioncollection bodyparts, object[] parameters, boolean isrequest)</stacktrace>                   <type>system.invalidoperationexception</type> 

what assume happening wcf service reading whole soap envelop 1 xml document, when encounters xml declaration (for parameter xmlsource) , interprets xml document whole soap envelope. crashes , says xml declaration must first part of document.

is there way fix or strip out xml declarations request before hits webservice?

the xml you're sending service invalid. according xml spec, xml declaration can appear in prolog of document. well-formed xml document composed of prolog + a root element. , xml declarations not allowed in element node.

you may want consider passing document xml declaration string (e.g., inside <!\[cdata\[ section, or escaping xml characters), you'll able receive xml "document" within xml request.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -