tags:

views:

50

answers:

1

Hi, I am trying to do some C# SOAP calls and can't seem to get any good examples on how to do it. I read an old question of mine about a SOAP call in PHP and thought maybe asking you guys to rewrite it in C# would be a good place to start.

Here is the PHP code:

$client = new SoapClient('http://www.hotelscombined.com/api/LiveRates.asmx?WSDL');

$client->__soapCall('HotelSearch', 
    array(
        array('request' => 
            array(
                'ApiKey' => 'THE_API_KEY_GOES_HERE', // note that in the actual code I put the API key in...
                'UserID' => session_id(),
                'UserAgent' => $_SERVER['HTTP_USER_AGENT'],
                'UserIPAddress' => $_SERVER['REMOTE_ADDR'],
                'HotelID' => '50563',
                'Checkin' => '07/02/2009',
                'Checkout' => '07/03/2009',
                'Guests' => '2',
                'Rooms' => '1',
                'LanguageCode' => 'en',
                'DisplayCurrency' => 'usd',
                'TimeOutInSeconds' => '90'
            ) 
        ) 
    )
);
+4  A: 

First step would be to create a proxy. Use the Add Service Reference dialog box in Visual Studio and provide the WSDL address: http://www.hotelscombined.com/api/LiveRates.asmx?WSDL.

Second step is to call the service:

using (var client = new LiveRatesSoapClient())
{
    var response = client.HotelSearch(new HotelSearchRequest
    {
        ApiKey = "THE_API_KEY_GOES_HERE",
        Checkin = new DateTime(2009, 7, 2),
        Checkout = new DateTime(2009, 7, 3),
        DisplayCurrency = "usd",
        Guests = 2,
        HotelID = 50563,
        LanguageCode = "en",
        Rooms = 1,
        TimeOutInSeconds = 90,
        UserAgent = "???",
        UserID = "???",
        UserIPAddress = "???"
    });
}

Note that depending on the WSDL some property names might be different than the ones I provided in my sample as I don't know the WSDL but Intellisense should help you.

There's a nice tutorial you might read.

Darin Dimitrov
@Darin - Thanks this was a great step one for me. I am having trouble though with your line one particularly the `LiveRatesSoapClient()` class, should it just automatically be there after I add the service reference? Because VS doesn't seem to know what I'm talking about
Andrew G. Johnson
You need to add the correct using. Place cursor over the `LiveRatesSoapClient` class, you should see a small red box at the bottom right corner of the word and then either click on it or Shift + Alt + F10 and import the correct using directive. I would recommend you reading some beginner tutorial on .NET in general before trying more advanced stuff.
Darin Dimitrov