doedje / jquery.soap

This script uses $.ajax to send a SOAP:Envelope. It can take XML DOM, XML string or JSON as input and the response can be returned as either XML DOM, XML string or JSON too.
352 stars 148 forks source link

Undefined request in beforeSend() #122

Closed AlexCln closed 6 years ago

AlexCln commented 6 years ago

Hi, I was try to make your lib work but without success.

Jquery soap version: 1.7.1 Jquery version : 2.2.1

Here is my code:

  var wsUrl = appUrl.replace(/\/+$/, "") + '/services/' + serviceName + '/' + methodName;
          MyApp.writeMessage("url : "+ wsUrl);

          $.soap({
            url: wsUrl,
            method: methodName,
            data: args,
            beforeSend: function(req){
              MyApp.writeMessage("request : " +req);
            },
            success: function success(soapResponse){
              MyApp.writeMessage("success : " + soapResponse);
            },
            error: function error(soapResponse){
              MyApp.writeMessage("error : " + soapResponse);
            }
          });

My app is a javascript Add-In for Word 2016. The output is :

url : http://my-server.com/MyApp/services/AuthenticationService/verifyUser
request : params1params2params3
error : Error: Unexpected Content: undefined

I already have take a look on Same Origin Policy. My reverse proxy is ok. My resquest doesn't look like your exemple.

May I miss something ? I don't understand why and where

Thanks for your time Regards Alex

doedje commented 6 years ago

what does your args look like? the request should indeed be a complete XML with SOAP namespaces and everything.....

AlexCln commented 6 years ago

Hi Doedje;

My args looks like :

args = {
   appId: "params1",
   username: "params2",
   password: "params3"
}

the request should indeed be a complete XML with SOAP namespaces and everything..... ==> Totally agree, but it doesn't... I don't understand why my request isn't encapsulated in a xml envelop. $.soap is correctly imported, everythings looks good

Update 26 september at 2pm: I've made an update on my $.soap implementation :

 $.soap({
            url: "http://myserver.com/myApp/services/AuthenticationService.AuthenticationServiceHttpSoap12Endpoint",
         method: "verifyUser",
          appendMethodToURL: false,
          enableLogging: true,
          soap12: true,
          namespaceQualifier: 'off',
      namespaceURL: 'http://my.server.com',
          data: args,
          context: document.body,
          beforeSend: function(req){
            MyApp.writeMessage(this);
          },
            success: function (soapResponse) {
            MyApp.writeMessage("Res: "+ JSON.stringify(soapResponse));
            },
            error: function (SOAPResponse) {
                // show error
            MyApp.writeMessage("SOAP error : " + SOAPResponse);
            }
      });

When I put a breakpoint at jquery.soap.js:742 I got this output :

`<?xml version="1.0" encoding="UTF-8"?>

params1 params2 params3 ` During the `return soapEnvelope.send() ` my `config.context` is empty, Is it normal or I just missed something in my implementation ? Anyway, in my console I got this error : `Mixed Content: The page at 'https://localhost:8443/assets/html/dialogs/loginDialog.html' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://myserver.com/myApp/services/AuthenticationService.AuthenticationServiceHttpSoap12Endpoint'. This request has been blocked; the content must be served over HTTPS. ` New update at 5pm : I got a new error : `Error: Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:*.myserver.com, DNS:myserver.com"` Looks like my certificate isn't correctly formed. Thanks Alexis
doedje commented 6 years ago

Ah, those certificates.......

Now I realise what might have happened with your xml when you printed:

request : params1params2params3

It looks like you print to something that is interpreting html, dropping all the xml that is wrapping your params1,2 and 3.... like what would happen when you put xml into an html-element on a website....

Why the config.context is empty I don't really know. I'll look into that.

Good luck with your project and certificates!

AlexCln commented 6 years ago

Thanks for your answers anyway !

It looks like you print to something that is interpreting html, dropping all the xml that is wrapping your params1,2 and 3.... like what would happen when you put xml into an html-element on a website....

==> Exactly this is what my MyApp.writeMessage looks like :

MyApp.writeMessage =  function writeMessage(text){
    $('.ms-MessageBar').hide();
    $('#messageBarError').show();
    $('#messageBarError .ms-MessageBar-text').append('<br/>'+text);
  }

If needed for people coming to my post this is how my $.soap looks like :

 $.soap({
            url: "https://localhost:8444/myApp/services/AuthenticationService.AuthenticationServiceHttpSoap11Endpoint",
         method: methodName,
          appendMethodToURL: false,
          enableLogging: true,
          namespaceQualifier: 'off',
      namespaceURL: 'http://myDistantServer.services.com',
          data: args,
          context: document.body,
          beforeSend: function(req){
            MyApp.writeMessage(this);
          },
            success: function (soapResponse) {
            MyApp.writeMessage("Res: "+ JSON.stringify(soapResponse));
            },
            error: function (SOAPResponse) {
            MyApp.writeMessage("SOAP error : " + SOAPResponse);
            }
      });

The url property is the url:port of my reverse proxy who redirect every request of this url:port to my Soap distant web server.

Hope it will help someone in the future. Thanks again Alex

doedje commented 6 years ago

You're welcome!