Solved

SOAP Request to XML Web Service with javascript

Posted on 2006-06-29
14
843 Views
Last Modified: 2007-12-19
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/
0
Comment
Question by:werD420
  • 6
  • 4
14 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 17016304
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");
  }
}

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17016311
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
  }
}

0
 

Author Comment

by:werD420
ID: 17019196
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");
  }
}
 
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17019682
When do you think is this question answered?
0
 

Author Comment

by:werD420
ID: 17020209
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
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:werD420
ID: 17020396
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>
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17021295
Grade A would not cost you more, but grade C cost you my sympathy ;-)
0
 

Author Comment

by:werD420
ID: 17025834
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



0
 

Author Comment

by:werD420
ID: 17025840
as for the quality of the answer would be answering the whole question
0
 

Author Comment

by:werD420
ID: 17027615
"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
 
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 17047340
Closed, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now