Consumption webservice with error: Unsupported content type

Asked

Viewed 111 times

1

My first question is: I can call the Webservice directly via JQUERY / AJAX or I need to have something in PHP or some other back-end language to accomplish integration?

If possible only with JQUERY / AJAX, follows the problem.

I have the following Webservice:

http://IP:PORTA/wsexecbo/WebServiceExecBO?wsdl

and in that Webservice i have the following function:

http://IP:PORTA/wsexecbo/WebServiceExecBO?wsdl/userLogin

that I send a user (no password) and it returns a token to me.

Follows my custom js.:

$(document).ready(function() {
var soapMessage = 
  "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" +
  "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ser='http://service.execbo.ws.framework.totvs.com'>" +
      "<soapenv:Header/>" +
      "<soapenv:Body>" +
      "<ser:userLogin>" +
      "<arg0>user</arg0>" +
      "</ser:userLogin>" +
      "</soapenv:Body>" +
  "</soapenv:Envelope>";

  var wsUrl = "http://IP:PORTA/wsexecbo/WebServiceExecBO?wsdl/userLogin";
  $.ajax({
      type: "POST",
      dataType: "xml",
      url: wsUrl,
      data: soapMessage,
      success: function(data) {
          console.log(data);
      },
      error: function(error) {
          console.log(error);
      }
  });
}); 

But it always comes back:

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
    <env:Header>
    </env:Header>
        <env:Body>
            <env:Fault xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
            <faultcode>env:Server</faultcode>
            <faultstring>
                Unsupported content type: application/x-www-form-urlencoded; charset=UTF-8
            </faultstring>
            </env:Fault>
        </env:Body>
</env:Envelope>

I did some tests putting these options:

contentType: "text/xml"
contentType: "application/xml"

But nothing solves it. Someone would know what is happening and how I can solve it?

  • the problem is in the body of the request, tries to give a console.log in the soapMessage and make sure it’s straight.

  • Apparently soapMessage is ok. Following is the console photo: https://i.imgur.com/g1LAHnz.jpg

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.