Tôi có dịch vụ web WCF và trình khách javascript kết nối với dịch vụ này qua AJAX bằng cách sử dụng SOAP 1.2. Những gì tôi muốn làm là để vượt qua một số tham số để nói cho AJAX SOAP gọi chỉ sử dụng một proxy giống như tôi thực hiện trong WCF Test Client bằng cách bỏ chọn "Bắt đầu proxy mới". Cách sử dụng một proxy trong AJAX javascript bằng cách sử dụng SOAP giống như WCF Test Client sử dụng
Và đây là SOAP gọi AJAX của tôi:
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);
}
}
Đây có phải là máy chủ của riêng bạn hoặc dịch vụ SOAP của bên thứ 3 không? Tôi tự hỏi vì các vấn đề của trang web chéo nếu bạn đang có khách hàng thực sự đăng xml thông qua chức năng này cho bên thứ ba SOAP ws. Tôi tin rằng hầu hết các trình duyệt sẽ không cho phép bạn đăng xml lên bên thứ ba trực tiếp qua js từ trang web gốc của bạn. Từ màn hình wcf của bạn, tôi lấy nó là nội bộ. Vì vậy, bạn có ý nghĩa gì bởi proxy sau đó cho mỗi trình duyệt của khách hàng? – williambq
@williambq Cảm ơn bạn đã bình luận. Đây là máy chủ của riêng tôi.không phải là bên thứ ba. – liorafar
Vì vậy, tôi nghĩ rằng bạn đang cố gắng để có được một proxy singleton tại chỗ? Vì vậy, mỗi yêu cầu tạo ra một thể hiện mới của proxy khi được gọi? – williambq