I can’t use the webservice

Asked

Viewed 171 times

0

I have the following webservice:

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

and in that WS i have the following function:

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

I send a user (no password) and he returns one token.

I would like to consume this WS directly from an HTML page with jQuery, but I’m 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");
       }
    });
});    

Always give me that mistake:

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

In the F12 found this mistake: Printscreen com o erro 500

What’s going on?

I can call the WS directly via AJAX or I need to have a server receiving the token and I get it from this server? Via SOAP-UI works.

EDIT:

As Leandro Angelo commented, the envelope was missing. I did the following:

$(document).ready(function() {
var soapMessage = 
  "<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 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 did some tests putting these options:

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

Unsuccessful. Has anyone ever had anything like it or knows the origin of this kind of problem?

  • Ah question is how you are wrapping your post, take a look at Soap ui and see the format it uses for sending, including if it accepts json or if you will have to mount an xml respecting the Ws contract

  • Thank you very much for your reply, but I haven’t been able to make it work yet. I enhanced the initial post with the new information, if you can help I really appreciate.

No answers

Browser other questions tagged

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