c# - WebService to return data in a certain format -


i trying replicate webservice provided company trying use testing environment.

the original webservice returns data like:

<?xml version="1.0" encoding="utf-8"?> <arrayofdoaccountmasters xmlns="http://tempuri.org/">   <doaccountmasters>     <masternum>int</masternum>     <mastername>string</mastername>     <errorcode>int</errorcode>     <errordescription>string</errordescription>   </doaccountmasters>   <doaccountmasters>     <masternum>int</masternum>     <mastername>string</mastername>     <errorcode>int</errorcode>     <errordescription>string</errordescription>   </doaccountmasters> </arrayofdoaccountmasters> 

at moment have following function:

<webmethod(description:="returns array 5 ids < x", enablesession:=true)> _ public function getcustomerids(id string) list(of string)     dim output new list(of string)()     dim sqlcommand sqlcommand = new sqlcommand( _      "select top 5 p.masternum, p.mastername, p.errorcode, p.errordescription person.person p businessentityid<" & id, connection)      connection.open()     dim dr = sqlcommand.executereader()     while dr.read         output.add(dr.item(0))     end while      connection.close()     return output  end function 

which returns following:

<?xml version="1.0" encoding="utf-8"?> <arrayofstring xmlns="http://tempuri.org/">   <string>string</string>   <string>string</string>   <string>string</string>   <string>string</string> </arrayofstring> 

apparently, method doesn't return data in same format. how can modify code make same method? how need format return data?

your method returning told - list of strings. service you're attempting imitate returning list of doaccountmasters. method needs return list of doaccountmasters output original service.

i recommend use wcf this, asmx web services legacy technology. in wcf use datacontract doaccountmasters, , normal service interface , class implements interface. (there more wcf below parts - you'll have host service in iis or other hosting solution):

<datacontract()> public class doaccountmasters      <datamember()>     public property masternum integer     <datamember()>     public property mastername string     <datamember()>     public property errorcode integer     <datamember()>     public property errordescription string endclass 

the interface:

<servicecontract()> public interface imyservice      <operationcontract()>     function getcustomerids(id string) list(of doaccountmasters) end interface 

the service implementation:

public class myservice      implements imyservice      public function getcustomerids(id string) list(of doaccountmasters)          dim output new list(of doaccountmasters)()          dim sqlcommand sqlcommand = new sqlcommand( _             "select top 5 p.masternum, p.mastername, p.errorcode, p.errordescription person.person p businessentityid<@id", connection)          connection.open()         sqlcommand.paramters.add("@id", sqldbtype.int, id)         dim dr = sqlcommand.executereader()         while dr.read             dim master doaccountmasters = new doaccountmasters()             master.masternum = convert.toint32(dr.item(0))             master.mastername = dr.item(1).tostring()             master.errorcode = convert.toint32(dr.item(2))             master.errordescription = dr.item(3).tostring()             output.add(master)         end while          connection.close()         return output     end function end class 

if must stick .asmx, use same class (minus datacontract , datamember attributes) , same logic:

public class doaccountmasters      public property masternum integer     public property mastername string     public property errorcode integer     public property errordescription string end class  <webmethod(description:="returns array 5 ids < x", enablesession:=true)> _ public function getcustomerids(id string) list(of doaccountmasters)      dim output new list(of doaccountmasters)()      dim sqlcommand sqlcommand = new sqlcommand( _         "select top 5 p.masternum, p.mastername, p.errorcode, p.errordescription person.person p businessentityid<@id", connection)      connection.open()     sqlcommand.parameters.add("@id", sqldbtype.int, id)     dim dr = sqlcommand.executereader()     while dr.read         dim master doaccountmasters = new doaccountmasters()         master.masternum = convert.toint32(dr.item(0))         master.mastername = dr.item(1).tostring()         master.errorcode = convert.toint32(dr.item(2))         master.errordescription = dr.item(3).tostring()         output.add(master)     end while      connection.close()     return output  end function 

the above codes utilize parameterized queries, , i'm making guess id integer based on sql command have.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -