Solved

Need help with JavaScript SOAP Request

Posted on 2013-12-02
10
491 Views
Last Modified: 2016-02-26
I seem to be having problems with this block of JavaScript, I do not get an error so I am using alert() to try and pinpoint the issue. I get the alert() before this block of code but not after the block of code. m_XML is declared in a block of code above this. (NOTE: This code was written in VBScript and I have been trying to convert it into JavaScript)

 m_XML = new XMLHttpRequest()

 m_XML.SetRequestHeader 'Content-Type' 'text/xml charset=utf-8';
 m_XML.SetRequestHeader 'DataType' 'xml';
 m_XML.SetRequestHeader 'SOAPAction' 'urn:getProfileSoap';
 m_XML.SetRequestHeader 'Host' '10.1.60.10:8443';
 m_XML.SetRequestHeader 'Expect' '100-continue';
 m_XML.SetRequestHeader 'Connection' 'Keep-Alive';

 m_XML.open('POST', 'https://10.1.60.10:8443/webdialer/services/WebdialerSoapService/', false);
0
Comment
Question by:AmbassadorSpock
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 14

Expert Comment

by:jb1dev
ID: 39690954
Don't you need parenthesis in your function calls?

 m_XML.setRequestHeader('Content-Type' 'text/xml charset=utf-8');
etc
etc

Also might try using lower case "s" when calling setRequestHeader()
0
 
LVL 14

Assisted Solution

by:jb1dev
jb1dev earned 250 total points
ID: 39690966
Oops and comma separate the parameters.
See an example here
http://msdn.microsoft.com/en-us/library/ie/ms536752%28v=vs.85%29.aspx

So this should be
  m_XML.setRequestHeader('Content-Type', 'text/xml charset=utf-8');
And same for the subsequent calls.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 39690989
@jb1dev is right.  Javascript is case sensitive.  Here's some more info: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:AmbassadorSpock
ID: 39690993
My bad
0
 

Author Comment

by:AmbassadorSpock
ID: 39691048
I still get the START: setRequestHeader alert but not the END: setRequestHeader alert. I have tried both ' and " in the setRequestHeader.

    m_XML = new XMLHttpRequest();

    alert('START: setRequestHeader');
    
    m_XML = new XMLHttpRequest();

    m_XML.setRequestHeader('Content-Type', 'text/xml charset=utf-8');
    m_XML.setRequestHeader('DataType', 'xml');
    m_XML.setRequestHeader('SOAPAction', 'urn:getProfileSoap');
    m_XML.setRequestHeader('Host', '10.1.60.10:8443');
    m_XML.setRequestHeader('Expect', '100-continue');
    m_XML.setRequestHeader('Connection', 'Keep-Alive');

    alert('END: setRequestHeader');

Open in new window

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39691085
From the page I linked above, you have to 'open' the xmlRequest before you can set the headers.
    alert('START: setRequestHeader');
    
    var m_XML = new XMLHttpRequest();
    m_XML.open("POST","ajax_test.asp",true);

    m_XML.setRequestHeader('Content-Type', 'text/xml charset=utf-8');
    m_XML.setRequestHeader('DataType', 'xml');
    m_XML.setRequestHeader('SOAPAction', 'urn:getProfileSoap');
    m_XML.setRequestHeader('Host', '10.1.60.10:8443');
    m_XML.setRequestHeader('Expect', '100-continue');
    m_XML.setRequestHeader('Connection', 'Keep-Alive');

    alert('END: setRequestHeader');

Open in new window

0
 

Author Comment

by:AmbassadorSpock
ID: 39691176
It seems to have problems with the XMLHttpRequest, is there another method JavaScript could use?
0
 
LVL 14

Expert Comment

by:jb1dev
ID: 39691294
You need to call open() on the request before setting the headers. Otherwise you get an Invalid State error.

    alert('START: setRequestHeader');

    m_XML = new XMLHttpRequest();

    m_XML.open('POST', 'http://localhost/', false);
    m_XML.setRequestHeader('Content-Type', 'text/xml charset=utf-8');
    m_XML.setRequestHeader('DataType', 'xml');
    m_XML.setRequestHeader('SOAPAction', 'urn:getProfileSoap');
    m_XML.setRequestHeader('Host', '10.1.60.10:8443');
    m_XML.setRequestHeader('Expect', '100-continue');
    m_XML.setRequestHeader('Connection', 'Keep-Alive');

    alert('END: setRequestHeader');

Open in new window

0
 

Accepted Solution

by:
AmbassadorSpock earned 0 total points
ID: 39692973
I can still never get to alert('SOAP Body');. Something with the XMLHttpRequest();

//SOAP_Request_GetUserProfile()
function SOAP_MakeCall() {
    var DeviceID = document.getElementById('DeviceID').value;
    var Internal = document.getElementById('Internal').value;
    var CCAgent = document.getElementById('CCAgent').value;
    var UserID = document.getElementById('UserID').value;
    var RequestText, ResponseHeader, f_URL, m_XML

    alert('Device ID: ' + DeviceID + ' Internal: ' + Internal + ' CCAgent: ' + CCAgent + ' UserID: ' + UserID);

    m_XML = new new ActiveXObject("Msxml2.XMLHTTP");

    alert('START: setRequestHeader');
    
    m_XML = new XMLHttpRequest();
    m_XML.open('POST', 'https://10.1.60.10:8443/webdialer/services/WebdialerSoapService/', false);
    m_XML.setRequestHeader('Content-Type', 'text/xml charset=utf-8');
    m_XML.setRequestHeader('DataType', 'xml');
    m_XML.setRequestHeader('SOAPAction', 'urn:getProfileSoap');
    m_XML.setRequestHeader('Host', '10.1.60.10:8443');
    m_XML.setRequestHeader('Expect', '100-continue');
    m_XML.setRequestHeader('Connection', 'Keep-Alive');
    
    alert('SOAP Body');

    RequestText = '<?xml version="1.0" encoding="utf-8"?>';
    RequestText = RequestText + '<soapenv:Envelope ';
    RequestText = RequestText + 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
    RequestText = RequestText + 'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ';
    RequestText = RequestText + 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ';
    RequestText = RequestText + 'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">';
    RequestText = RequestText + '<soapenv:Body>';

        RequestText = RequestText + '<tns:makeCallSoap>';
            RequestText = RequestText + '<cred href="#id1" />';
            RequestText = RequestText + '<dest xsi:type="xsd:string">9**13218165105864</dest>';  //Variable phone number for Click To Dial
            RequestText = RequestText + '<prof href="#id2" />';
        RequestText = RequestText + '</tns:makeCallSoap>';

        RequestText = RequestText + '<tns:Credential id="id1" xsi:type="tns:Credential">';  //'Hard Coded Credentials for LINKS
            RequestText = RequestText + '<userID xsi:type="xsd:string">linkuser</userID>';
            RequestText = RequestText + '<password xsi:type="xsd:string">bl3S$you</password>';
        RequestText = RequestText + '</tns:Credential>';

        RequestText = RequestText + '<tns:UserProfile id="id2" xsi:type="tns:UserProfile">';  //Variable Credentials for LINKS
            RequestText = RequestText + '<user xsi:type="xsd:string">' + UserID + '</user>';
            RequestText = RequestText + '<deviceName xsi:type="xsd:string">' + DeviceID + '</deviceName>';  //Variable Device Name for Click TO Dial
            RequestText = RequestText + '<lineNumber xsi:type="xsd:string">' + Internal + '</lineNumber>';  //Internal or CCAgent
            RequestText = RequestText + '<supportEM xsi:type="xsd:boolean">false</supportEM>';
            RequestText = RequestText + '<dontAutoClose xsi:type="xsd:boolean">false</dontAutoClose>';
            RequestText = RequestText + '<dontShowCallConf xsi:type="xsd:boolean">false</dontShowCallConf>';
        RequestText = RequestText + '</tns:UserProfile>';    
        

    RequestText = RequestText + '</soapenv:Body>';
    RequestText = RequestText + '</soapenv:Envelope>';

//    m_XML.setRequestHeader('Content-Length', length(RequestText));
    m_XML.Send(RequestText);

    alert('COMPLETE');
}

Open in new window

0
 

Author Closing Comment

by:AmbassadorSpock
ID: 39705690
Going to go a different route but I wanted to make sure JB1DEV and DaveBaldwin got some recognition and points for assisting me.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

624 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