skip to Main Content

I have web service solution in Visual Studio with one parameter :

Public Function CheckPalletInLocation(location As String) As String

       Dim ScaleConnnection As New SqlClient.SqlConnection("MYCONNEXION")
       Dim ScaleCommand As New SqlClient.SqlCommand
       ScaleCommand.Connection = ScaleConnnection
       ScaleConnnection.Open()
       ScaleCommand.CommandText = "SELECT DISTINCT LOGISTICS_UNIT FROM LOCATION_INVENTORY WHERE LOCATION = '" &
       location & "'"
       Return ScaleCommand.ExecuteScalar()
       ScaleConnnection.Close()

       'Return "True"
   End Function

When I launch solution, webservice works. It return value.
Now I want to call it in HTML page with ajax code :

<pre><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
        <title>TEST WEB SERVICE</title>
        <script type="text/javascript" src="jquery-3.4.1.js"></script>
</HEAD>

    <BODY onload="Click_BB();">PAGE
    <script>

    function Click_BB()
    {
        $.ajax({
          type: 'post',
          url: 'https://localhost:44341/WebService1.asmx?op=CheckPalletInLocation',
          contentType: "application/xml",
          data: { location: '110-01-03-10' },
          success: function (d) 
              {
                alert(d);
              },
          failure: function (response) 
              {
                debugger;
                alert(response.d);
              }
        });
    }
    
    </script>
    </BODY>
</HTML>

I always have this error in the response page :

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="fr">System.Web.Services.Protocols.SoapException: Le serveur n'a pas pu traiter la demande. ---> System.Xml.XmlException: Données non valides au niveau racine. Ligne 1, position 1.

I transale : server cannot process. Invalid data root, line 1 position 1

Can someone help please ?

Thanks

I tried to change AJAX code, I would like to have the result of my web service in HTML page. Until now I have error 500

2

Answers


  1. Chosen as BEST ANSWER

    it works I put this code :

    var soapMessage = '<?xml version="1.0" encoding="utf-8"?>'+
                    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                        '<soap:Body> ' +
                        '<CheckPalletInLocation  xmlns="http://tempuri.org/"> ' +
                             '<location>110-01-03-10</location> ' +
                        '</CheckPalletInLocation> ' +
                        '</soap:Body>`' +
                    '</soap:Envelope>';
    

  2. You want to send XML (a SOAP envelope) to the server with the correct location data:

    Add a variable containing a valid soap-envelope as a string to be used by your webservice. Add these properties to the Click_BB function:

    dataType: "xml",
    data: soapMessage,

    You probably want to setup the soap:Body like this:

    <soap:Body>
        <CheckPalletInLocation>
             <location>110-01-03-10</location> 
        </CheckPalletInLocation>
    </soap:Body>`
    

    Change the function:

    function Click_BB()
    {
        $.ajax({
          type: 'post',
          url: 'https://localhost:44341/WebService1.asmx?op=CheckPalletInLocation',
          contentType: "application/xml",
          dataType: "xml", 
          data: soapMessage, 
          success: function (d) 
              {
                alert(d);
              },
          failure: function (response) 
              {
                debugger;
                alert(response.d);
              }
        });
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search