admin管理员组

文章数量:1335611

I have WCF web Service and javascript client which connects to this service via AJAX using SOAP 1.2 . What i wanna do is to pass some parameter to tell the AJAX SOAP call to use only one proxy the same as I do it in the WCF Test Client by unchecking the "Start a new proxy" .

And this is my SOAP AJAX call:

DoSoapAjax: function (soapMethodName, data, successHandler, errorHandler, isAsync, currentInstance) {
    var service = this;
    var soapResult    = soapMethodName + "Result";
    var soap12WithWsHttpBindRequest ='<s:Envelope xmlns:a="" xmlns:s="">' +
                      '<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>;/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 : 
    $.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);
        }
    }  

I have WCF web Service and javascript client which connects to this service via AJAX using SOAP 1.2 . What i wanna do is to pass some parameter to tell the AJAX SOAP call to use only one proxy the same as I do it in the WCF Test Client by unchecking the "Start a new proxy" .

And this is my SOAP AJAX call:

DoSoapAjax: function (soapMethodName, data, successHandler, errorHandler, isAsync, currentInstance) {
    var service = this;
    var soapResult    = soapMethodName + "Result";
    var soap12WithWsHttpBindRequest ='<s:Envelope xmlns:a="http://www.w3/2005/08/addressing" xmlns:s="http://www.w3/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/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./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);
        }
    }  
Share Improve this question edited Aug 16, 2013 at 21:57 Mario S 12k24 gold badges41 silver badges47 bronze badges asked Nov 29, 2012 at 14:51 liorafarliorafar 2,3645 gold badges19 silver badges40 bronze badges 3
  • Is this to your own server or a 3rd party SOAP service? Am wondering because of the cross site issues if you are having the client actually post xml via this function to the third party SOAP ws. I believe most browsers won't allow you to post xml to a 3rd party directly via js from your originating web page. From your wcf screen, I take it is internal. So what do you mean by proxy then per the browser client? – williambq Commented Jun 12, 2013 at 23:21
  • @williambq Thanks for your ment. This is my own server. not a 3rd party. – liorafar Commented Jun 16, 2013 at 12:35
  • 2 So, I think you are trying to get a singleton proxy in place? So each request does create a new instance of the proxy when called? – williambq Commented Jun 24, 2013 at 18:00
Add a ment  | 

3 Answers 3

Reset to default 1

I'll start off by saying I do not know the specific answer to this, but my approach would be to sniff the traffic from your WFC Test Client to see if it is adding any parameters to the call which you could add to your request header on your AJAX call.

Fiddler might do the job though I'm not sure it will catch all http traffic - mostly it's geared to browsers. There are other tools with more or less capability and ease of use, like wire shark, ether, and so on.

I would guess there is some other request parameter outside the SOAP envelope body being transmitted from the test client that you should be able to see. It's the only way I can imagine the test client would be able to municate this without modifying your SOAP message.

If you can find the name and value, you can add it to your data: parameter as another name-value JSON entity.

liorafar: I assume you are running Javascript from a browser as it host. If so it is not possible unless you allow the javascript change some behavoiur of your host which is with clients aproval for every excecution that the browser identifies as security risk. Consider that: 1) Javascript doesnt take control over the connection configuration, it only use the envirionment provided by the host where it is running, in this case the browser but can be on the server side too. 2) In case you say "ok, lets force this", the only way it e to my mind is to make an instance of your host or any object of the client host and force to change the connection... and by that moment the browser will detect your javascript as a security risk and cerntanly you should create a script for every browser in the market, because every one has it way to handle this... the only good news on this is that with IE you can change the configuration for Chrome too!!

What I will do to solve this issue is to ask to the IT people to config the browsers with some exceptino rule over the proxy in the browsers (if you are into a pany).

I hope this can help in a way or another!!

Gabriel

You can put your soap request in Fiddler and then execute you will get the response. For that response type. When you get response view it in mode you want.

本文标签: How to use one proxy in javascript AJAX using SOAP the same as WCF Test Client useStack Overflow