开发者

Help me convert this PHP SOAP code to C#

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' =>开发者_如何学C $_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'
            ) 
        ) 
    )
);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜