我有 WCF web 服务和 javascript 客户端,它们使用 SOAP 1.2 通过 AJAX 连接到该服务。我想做的是通过取消选中“启动新代理”来传递一些参数来告诉 AJAX SOAP 调用只使用一个代理,就像我在 WCF 测试客户端中所做的一样。
这是我的 SOAP AJAX 调用:
DoSoapAjax: function (soapMethodName, data, successHandler, errorHandler, isAsync, currentInstance) {
var service = this;
var soapResult = soapMethodName + "Result";
var soap12WithWsHttpBindRequest ='<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
'<s:Header>' +
'<a:Action s:mustUnderstand="1">' + this.serviceContractNamespace + '/' + this.interfaceName + '/' + soapMethodName + '</a:Action>' +
'<a:MessageID>urn:uuid:605ea0c6-d09b-46bf-b61d-e61b377a135b</a:MessageID>' +
'<a:ReplyTo>' +
'<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>' +
'</a:ReplyTo>' +
'<a:To s:mustUnderstand="1">' + this.tenantAdminService + '</a:To>' +
'</s:Header>' +
'<s:Body>';
if (data == emptyString)
{
soap12WithWsHttpBindRequest +=
'<' + soapMethodName + ' xmlns="' + this.serviceContractNamespace + '" />';
}
else
{
soap12WithWsHttpBindRequest +=
'<' + soapMethodName + ' xmlns="' + this.serviceContractNamespace + '">' +
data +
'</' + soapMethodName + '>';
}
soap12WithWsHttpBindRequest +=
'</s:Body>' +
'</s:Envelope>';
// in order for ajax to work on jQuery 1.8.2 we need to enable the following.
// found this answer on the link : http://stackoverflow.com/questions/9160123/no-transport-error-w-jquery-ajax-call-in-ie
$.support.cors = true;
// variable to save successData
var responseData = null;
// SOAP 1.2 query
var response = $.ajax({
type: "POST",
url: this.tenantAdminService,
data: soap12WithWsHttpBindRequest,
contentType: "application/soap+xml",
dataType: "xml",
processData: false,
async: isAsync,
success: function (data, status, xmlHttpRequest) {
responseData = data;
// inserting all data results into dictionary
var responseResults = {};
// delegating success function
if (successHandler != null)
{
responseResults = service.ParseResponse(soapMethodName, data);
successHandler(responseResults, currentInstance);
}
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
if (errorHandler != null)
{
errorHandler(xmlHttpRequest, textStatus, errorThrown, currentInstance);
}
else if (!isAsync)
{
alert("Error : " + errorThrown);
alert("Error Description : " + xmlHttpRequest.responseText);
}
return;
}
});
if (!isAsync)
{
return service.ParseResponse(soapMethodName, response.responseXML);
}
}