c# - Parse exception response posting XML using webclient -


i need post xml content external service (wfs) not under control. create simple document equivalent following (as required service):

<getcapabilities    service="wfs"    xmlns="http://www.opengis.net/wfs"    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"    xsi:schemalocation="http://www.opengis.net/wfs    http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/> 

i creating post request using webclient.uploaddata , getting parse exception response external service:

<ows:exception exceptioncode="noapplicablecode">     <ows:exceptiontext>org.xml.sax.saxparseexception; linenumber: 1; columnnumber: 1; content not allowed in prolog.content not allowed in prolog.</ows:exceptiontext> </ows:exception> 

i cannot provide full working example since cannot disclose uri of external service using, here code anyway (with uri omitted):

class program {     static void main(string[] args)     {         var xml = getcapabilities();         using (var client = new webclient())         {             using (var ms = new memorystream())             {                 try                 {                     xml.save(ms, saveoptions.disableformatting);                     var res = client.uploaddata("https://url-to-wfs-omitted", ms.toarray());                     var doc = xdocument.parse(encoding.utf8.getstring(res));                 }                 catch (webexception)                 {                  }             }         }     }      static xdocument getcapabilities()     {         // namespaces         var xmlns = xnamespace.get("http://www.opengis.net/wfs");         var xsi = xnamespace.get("http://www.w3.org/2001/xmlschema-instance");          // document         var doc = new xdocument();         var ele = new xelement(xname.get("getcapabilities", xmlns.namespacename));         ele.setattributevalue("service", "wfs");         ele.setattributevalue(xname.get("schemalocation", xsi.namespacename),             "http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd");         doc.add(ele);          return doc;     } } 


Comments