如何在使用SOAP的javascript AJAX中使用一个代理与WCF Test Client使用相同

lio*_*far 21 javascript ajax wcf proxy soap

我有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);
        }
    }  
Run Code Online (Sandbox Code Playgroud)

J E*_* II 1

首先我会说我不知道​​这个问题的具体答案,但我的方法是嗅探来自 WFC 测试客户端的流量,看看它是否向调用添加了任何可以添加到请求标头的参数在您的 AJAX 调用中。

Fiddler可能会完成这项工作,尽管我不确定它是否会捕获所有 http 流量 - 大多数情况下它是针对浏览器的。还有其他一些或多或少具有功能和易用性的工具,例如wire sharkether等。

我猜想您应该能够看到从测试客户端传输的 SOAP 信封正文之外还有一些其他请求参数。这是我想象的测试客户端能够在不修改 SOAP 消息的情况下进行通信的唯一方法。

如果您可以找到名称和值,则可以将其作为另一个名称-值 JSON 实体添加到 data: 参数中。