Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help with JavaScript SOAP Request

Posted on 2013-12-02
10
Medium Priority
?
522 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
  • 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 1000 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 84

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

876 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