Link to home
Start Free TrialLog in
Avatar of werD420
werD420

asked on

SOAP Request to XML Web Service with javascript

Hey all im using the following code which appears to be a bit buggy :S im looking to consume a web service called hint that is sitting on a development server localhost:3601 it takes one input a string called term
here's my code

              <script type="text/javascript" language=javascript>
 
  var xmlHttp;
  var  strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"+
           " <soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
      
          " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
      
          " xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" +
      
          "  <soap12:Body>" +
      
          "    <hint xmlns='http://microsoft.com/webservices'>" +
      
          "    <Term>b</Term></hint>" +
      
          "  </soap12:Body>" +
      
          "</soap12:Envelope>";

function showHint(str)
{
 
if (str.length > 0)
{
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open('POST', url , true)
xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8")
if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
alert("here");
xmlHttp.send(strEnvelope)
}
}
}
</script>

Im not getting any errors but the alert never fires also im not sure what command i should use to get the response text im sure its something obvious but im not at that point yet any way. I appreciate  any help i can get/
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

The third parameter in this statement does say: asynch=true
Also you do NOT fire the request.
The request is fired first after sen() call, not with the open() call.
But because you wait for "complete" you never start the request.
The asynch=true requires that you assign the state checking to a separate function called by callback reference at: onreadystatechange
Like this:

function showHint(str){
  if (str.length > 0){
    var url="http://localhost:3601/WebSite2/hint.asmx/hint";
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttp.open('POST', url , true)
    xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8");
    xmlHttp.onreadystatechange = checkState;
    xmlHttp.send(strEnvelope)
  }
}

function checkState(){
  if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
    alert("here");
  }
}

And my method of doing is to use: asynch=false
Like this:

function showHint(str){
  if (str.length > 0){
    var url="http://localhost:3601/WebSite2/hint.asmx/hint";
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttp.open('POST', url , false);  // not asynch
    xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8");
    xmlHttp.onreadystatechange = checkState;
    xmlHttp.send(strEnvelope)
     alert("here");  // when you are here is the http request finished
  }
}

Avatar of werD420
werD420

ASKER

Thanks for the post! Ive adjusted my code and the alert fires. I am stuck on how i interpret the response. I know I can send the response to a span or text box but i dont know what variable holds this info. Thanks again for your help


          <script type="text/javascript" language=javascript>
 
  var xmlHttp;
  var  strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"+
           " <soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
      
          " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
      
          " xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" +
      
          "  <soap12:Body>" +
      
          "    <hint xmlns='http://microsoft.com/webservices'>" +
      
          "    <Term>b</Term></hint>" +
      
          "  </soap12:Body>" +
      
          "</soap12:Envelope>";

function showHint(str)
{
 
if (str.length > 0)
{
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open('POST', url , true)
xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8")
 xmlHttp.onreadystatechange = checkState;
xmlHttp.send(strEnvelope)
}
}
function checkState(){
  if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
    alert("here");
  }
}
 
When do you think is this question answered?
Avatar of werD420

ASKER

no it isnt my goal is to get this response from a web service, but thanks for your continued help.

---------------
quote from original post
"also im not sure what command i should use to get the response text im sure its something obvious but im not at that point yet any way. I appreciate  any help i can get/"
------------
I have gotten to this point before but had no alert but I cant seem to pull the response and display it.

I have tried

alert(xmlHttp.getResponseHeader) 'object doesn't support this property or method
alert(xmlHttp.responseText) 'alert is a blank screen
alert(xmlHttp.responseXML) 'alert is [object]

any clue on how to get this result displayed is what I need. I dont need help with styles or with getting the web service running or with permissions I only need help with the javascript required to capture the response which should look like

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <hintResponse xmlns="http://microsoft.com/webservices/">
      <hintResult>string</hintResult>
    </hintResponse>
  </soap12:Body>
</soap12:Envelope>

Thanks again and I appreciate your assistance
Avatar of werD420

ASKER

Here is the updated code im not sure what i need to do here
           
  <script type="text/javascript" language=javascript>
 
  var xmlHttp;
  var  strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"+
           " <soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
      
          " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
      
          " xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" +
      
          "  <soap12:Body>" +
      
          "    <hint xmlns='http://microsoft.com/webservices'>" +
      
          "    <Term>b</Term></hint>" +
      
          "  </soap12:Body>" +
      
          "</soap12:Envelope>";

function showHint(str)
{
 
if (str.length > 0)
{
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open('POST', url , true)
xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8")
xmlHttp.send(strEnvelope)
xmlHttp.onreadystatechange = checkState;
}
}
function checkState(){
  if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
   placeHint(xmlHttp.responseXML);
     }
  else{
  alert("Not Complete");
  }
}
 function placeHint(xmlresponse) {
 alert(xmlresponse);
}

</script>
Grade A would not cost you more, but grade C cost you my sympathy ;-)
Avatar of werD420

ASKER

apologies, I gave him a C because 1 of this comment
"When do you think is this question answered?"
 
I had clearly asked for what should be called to get the response text and he had not answered it then when i reposted i again clarified what my question was when I stated

"Thanks for the post! Ive adjusted my code and the alert fires. I am stuck on how i interpret the response. I know I can send the response to a span or text box but i dont know what variable holds this info. Thanks again for your help"

I felt this his response was was clearly stating that I was asking too much of him. I pay to be on this site because i dont have time to argue back and forth about miniscule things. I do it because i need quick answers to issues.
I spent the extra time to figure this out and stopped progress on this and other things by doing so. and not to mention he didnt respond at all until i graded it then it was almost instantly he was looking down on me and couldnt sympathize for the "pathetic" PAYING CUSTOMER that to me is unacceptable.

again apologies for this but twice he posted nonrelevant things to the issue so a C i stand firm on



Avatar of werD420

ASKER

as for the quality of the answer would be answering the whole question
Avatar of werD420

ASKER

"But if someone does not answer it, don't give them a C simply to punish them." .......... I gave him a C b/c he overlooked half the question and expected the question to be over not to punish him.. but to show you the moderator this deplorable service
First... I m not punishing anyone but myself when it comes down to it.. I had to waste my time to find the solution to this miniscule client side javascript when i should be concentrating on bigger and better things on an application level. In the past 6 months ive given your site 60 dollars and asked 4 questions... None of them were answered until after I figured it out myself and posted about it.. And most recently Ive had to waste twenty minutes of my time with this post......

Im cancelling my account.. I think that the Customer Service here is struggling hard.    I am the customer.. I pay you money you do what is agreed on not what makes the lol "experts" happy. So you can have these points or you can take them back or you can feed them to your dog i dont care.. Just know that the customer service you and zvonko provided cost you a two year - life customer and i will not be the last...

DrewG
MCP,MCAD.MCSD
 
ASKER CERTIFIED SOLUTION
Avatar of GhostMod
GhostMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial