我正在尝试进行一些C#SOAP调用,似乎无法获得有关如何执行此操作的任何好示例。我在PHP中读了一个关于SOAP调用的old question,并且认为可能要求你们用C#重写它将是一个很好的起点。
这是PHP代码:
$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'
)
)
)
);
答案 0 :(得分:4)
第一步是创建代理。使用Visual Studio中的Add Service Reference对话框并提供WSDL地址:http://www.hotelscombined.com/api/LiveRates.asmx?WSDL
。
第二步是致电服务:
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 = "???"
});
}
请注意,根据WSDL,某些属性名称可能与我在示例中提供的属性名称不同,因为我不知道WSDL,但Intellisense应该可以帮助您。
你可能会读到一个很好的tutorial。