21

我有 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);
        }
    }  
4

3 回答 3

1

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

Fiddler可能会完成这项工作,但我不确定它是否会捕获所有 http 流量 - 主要是针对浏览器的。还有其他一些功能或多或少且易于使用的工具,如wire sharkether等。

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

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

于 2013-09-03T16:32:10.137 回答
0

你可以把你的soap请求放在Fiddler中然后执行你会得到响应。对于该响应类型。当您获得响应时,以您想要的模式查看它。

于 2013-10-01T13:54:35.487 回答
0

liorafar:我假设您正在从浏览器运行 Javascript,因为它是托管的。如果是这样,除非您允许 javascript 更改您的主机的某些行为,否则这是不可能的,这需要客户端批准浏览器识别为安全风险的每次执行。考虑一下:1)Javascript不控制连接配置,它只使用运行它的主机提供的环境,在这种情况下是浏览器,但也可以在服务器端。2)如果您说“好的,让我们强制执行此操作”,我想到的唯一方法是创建您的主机或客户端主机的任何对象的实例并强制更改连接......到那时浏览器会将您的 javascript 检测为安全风险,因此您应该为市场上的每个浏览器创建一个脚本,

为了解决这个问题,我将要求 IT 人员为浏览器配置一些例外规则,而不是浏览器中的代理(如果您进入公司)。

我希望这可以在某种程度上有所帮助!

加布里埃尔

于 2013-09-21T21:26:47.773 回答