我需要使用 SOAP 向 Experian 服务发出请求。
文档令人震惊,给出的示例代码更糟糕。所以我希望有人能提供帮助。
首先,我只想从测试调用中获得响应,使用 https://ws.ondemand.qas.com/ProOnDemand/V3/ProOnDemandService.asmx?op=DoGetExampleAddresses在那之后,我很确定我能解决问题。
有人能帮忙吗?
///Service Reference
Experian.QAS.QAAuthentication authentication = new Experian.QAS.QAAuthentication();
authentication.Username = "username";
authentication.Password = "password";
Experian.QAS.QAQueryHeader header = new Experian.QAS.QAQueryHeader();
header.QAAuthentication = authentication;
Experian.QAS.QAGetExampleAddresses body = new Experian.QAS.QAGetExampleAddresses();
body.Country = "GBR";
body.Layout = "QADefault";
//I think this is the wrong call to post the request
Experian.QAS.DoGetExampleAddressesRequest request = new Experian.QAS.DoGetExampleAddressesRequest(header, body);
代码最后一行的注释是正确的,那是操作的 SOAP 请求对象,而不是操作本身。
在示例代码的某处是否有继承自 SoapHttpClientProtocol
的类(例如称为 QASOnDemandIntermediary
)?
您需要实例化该类的一个实例,将您的身份验证对象分配给它,然后在执行您需要执行的操作的客户端上调用该方法,例如:
// Create authentication object
QAAuthentication authentication = new QAAuthentication();
authentication.Username = "MyUserName";
authentication.Password = "MyPassword";
// Create SOAP header and assign authentication parameters to it
QAQueryHeader header = new QAQueryHeader();
header.QAAuthentication = authentication;
// Create service client
QASOnDemandIntermediary client = new QASOnDemandIntermediary();
client.QAQueryHeaderValue = header;
// Create service request
QAGetExampleAddresses request = new QAGetExampleAddresses();
request.Country = "GBR";
request.Layout = "QADefault";
// Call the web service
QAExampleAddress[] result = client.DoGetExampleAddresses(request);
// Use the result
foreach (var example in result)
{
// Use the examples
}
我无法访问您正在使用的确切示例代码,因此我使用的一些类型名称可能不是 100% 正确,但它们应该是相似的。
我是一名优秀的程序员,十分优秀!