views:

91

answers:

3

I am working with some web services and I want to pass the array of request to the web service at once and the output should be returned once for the whole array of request.

For example, let's say I am requesting the city details by city name. I want to build the array of city names and pass it to the web service and get all the details in one response.

I am using ASP.NET

<AirAvailability_6_2>
<AirAvailMods>
<GenAvail>
<NumSeats>1</NumSeats>
<Class><![CDATA[ ]]></Class>
<StartDt>20091214</StartDt>
<StartPt>LON</StartPt>
<EndPt>AAH</EndPt>
<StartTm>1200</StartTm>
<TmWndInd>D</TmWndInd>
<StartTmWnd>0800</StartTmWnd>
<EndTmWnd>1400</EndTmWnd>
<FltTypeInd></FltTypeInd>
<StartPtInd></StartPtInd>
<EndPtInd></EndPtInd>
<IgnoreTSPref></IgnoreTSPref>
</GenAvail>
</AirAvailMods></AirAvailability_6_2>

<AirAvailability_6_2>
<AirAvailMods>
<GenAvail>
<NumSeats>1</NumSeats>
<Class><![CDATA[ ]]></Class>
<StartDt>20091214</StartDt>
<StartPt>LON</StartPt>
<EndPt>AAH</EndPt>
<StartTm>1200</StartTm>
<TmWndInd>D</TmWndInd>
<StartTmWnd>0800</StartTmWnd>
<EndTmWnd>1400</EndTmWnd>
<FltTypeInd></FltTypeInd>
<StartPtInd></StartPtInd>
<EndPtInd></EndPtInd>
<IgnoreTSPref></IgnoreTSPref>
</GenAvail>
</AirAvailMods></AirAvailability_6_2>
+2  A: 

declare the web method to accept an array. Declare the web method to return an array.

[WebMethod]
public CityDetails[] GetCityDetails(string[] names)
{ 
    /// blah blah
}
tster
i have edited my question and add the request code, i have this request to pass to the web service...now i want to make the array of this request and send it to the web service..i try it but it's returning me error same multiple tags...can u tell me how to write this request in array....
Sikender
A: 

If you are talking about an existing web service with an API you have no control over - you will have to stick with what this service offers. In other words if the existing API does not provide for batching requests you will have to feed the service one request at a time.

If, on the other hand, you are building the service yourself - noting prevents you from spelling out the API so that it can take an array of requests.

mfeingold
A: 

If you have control over both sides of the connection and they're both managed code, then you could create the custom object (serializable) and setup the web method to take in that object as its parameter.

I did this recently using JSON (giving me access from the client side of a web page). You set up the web service to accept a string parameter, and use a JSON Deserializer (DataContractJsonSerializer is one choice) to convert the request to your custom object.

This gives you the ability to pass in the specifics on multiple requests, and pass the results back out the same way (a custom collection object).

Let me know how this works out for you.'

Gabriel

Gabriel McAdams