I can not use webservice

0

I have the following webservice :

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

In this WS I have the following function:

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

I would like to consume this WS directly from an HTML page with jQuery , however I am not getting it.

custom.js:

$(document).ready(function() {
  var apiurl = 'http://IP:PORTA/wsexecbo/WebServiceExecBO?wsdl/userLogin';
  var user = 'teste';
  var a = new XMLHttpRequest();

  a.open('POST',apiurl,true),
    $.ajax({
       url: apiurl,
       type: "POST",
       data: JSON.stringify({user}),
       dataType: "json",
       contentType: "application/json; charset=utf-8",
       success: function (data) {
         alert("Result: "+data);
       },
       error: function (xhr) {
          alert("Error");
       }
    });
});    

I always get this error:

Failed to load http://IP:PORTA/wsexecbo/WebServiceExecBO?wsdl/userLogin: Response for preflight has invalid HTTP status code 500

No F12 found this error:

What'shappening?

CanIcallWSdirectlyviaAJAXordoIneedtohaveaserverreceivingthetokenandIgetthatserver?ViaSOAP-UIworks.

EDIT:

Ascolleague@LeandroAngelocommented,theenvelopewasmissing.I'vedonethefollowing:

$(document).ready(function(){varsoapMessage="<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";
  $.ajax({
      type: "POST",
      dataType: "xml",
      url: wsUrl,
      data: soapMessage,
      crossDomain: true,
      success: function(data) {
          console.log(data);
      },
      error: function(error) {
          console.log(error);
      }
  });
});

Now it seems like I'm getting somewhere, but the following problem is happening:

<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 made some tests by putting these options:

contentType: "application/json; charset=utf-8"
contentType: "text/xml"
contentType: "application/xml"

Unsuccessful. Has anyone ever had something like this or did you know the source of this kind of problem?

    
asked by anonymous 08.12.2017 / 19:08

0 answers