ASP.Net Web APi C# - GetAsync not returning XML response content -


i calling external service using getasync() , passing parameters in query string. when check content in response, don't see returned, returns 200 ok , in fiddler returns me xml response correctly. need xml response de-serialize c# object , further save db.

things tried:

1) tried adding setting in global- app_start(), didn't help

globalconfiguration.configuration.formatters.xmlformatter.usexmlserializer = true; 

2) created object , tried sent via getaysnc, didn't either.

public class request     {         [xmlelement]         public string xml { get; set; }         [xmlelement]         public list<string> pronumber { get; set; }     } 

2) should try passing parameters in query string , expect json result? if add mediatyperformatter application/json?

here code:

public async task<httpresponsemessage> getdata() {     string requeststring = "&xml=y&pronumber=82040x,03117x";     string result = "";      string url = @"http://my.yrc.com/dynamic/national/servlet?controller=com.rdwy.ec.rextracking.http.controller.publictrailerhistoryapicontroller";     try     {         using (var client = new httpclient())         {             client.baseaddress = new uri(url);             client.defaultrequestheaders.accept.clear();             client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/xml"));              httpresponsemessage response = await client.getasync(url+requeststring);              if (response.issuccessstatuscode)             {                 return response;             }         }     }     catch (exception ex)     {         result = ex.message;     }     return null; } 

edit:

                        shipments scp = null;                         xmlrootattribute xroot = new xmlrootattribute();                         xroot.elementname = "shipment";                         xroot.isnullable = true;                         xmlserializer serializer = new xmlserializer(typeof(shipment), xroot);                      using (stream stream = response.content.readasstreamasync().result)                     {                         scp = (shipments)serializer.deserialize(stream);                     } 

model:

public class shipments     {         [xmlarrayitem(type = typeof(shipment))]         public shipment[] shipment;     }      public class shipment     {         [xmlattribute()]         public int returncode { get; set; }         .................         .............. 

getting error:<shipments xmlns=''> not expected.

any on appreciated.

thanks, wh

this worked me -

var client = new httpclient(); var data = client.getstringasync("http://my.yrc.com/dynamic/national/servlet?controller=com.rdwy.ec.rextracking.http.controller.publictrailerhistoryapicontroller&xml=y&pronumber=82040x,03117x").result; var ser = new xmlserializer(typeof(shipments)); var t = (shipments)ser.deserialize(new stringreader(data));   public class shipment {     public string returncode { get; set; }     public string returnmessage { get; set; }     public string freightbillnumber { get; set; }     //props }  [xmlroot(elementname = "shipments")] public class shipments {     [xmlelement(elementname = "shipment")]     public list<shipment> shipment { get; set; } } 

edit

this works -

var data = client.getstreamasync("http://my.yrc.com/dynamic/national/servlet?controller=com.rdwy.ec.rextracking.http.controller.publictrailerhistoryapicontroller&xml=y&pronumber=82040x,03117x").result; 

edit

works -

var client = new httpclient(); var data = client.getasync("http://my.yrc.com/dynamic/national/servlet?controller=com.rdwy.ec.rextracking.http.controller.publictrailerhistoryapicontroller&xml=y&pronumber=82040x,03117x").result;  var ser = new xmlserializer(typeof(shipments)); var t = (shipments)ser.deserialize(data.content.readasstreamasync().result); 

Comments