Solved

Need help with JavaScript SOAP Request

Posted on 2013-12-02
10
463 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 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 82

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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 82

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Summernote and form validation 10 42
html input clean up 3 32
(URGENT) Help HTML and CSS Resizing Images 2 20
HTML CSS 7 19
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

758 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

22 Experts available now in Live!

Get 1:1 Help Now