Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help with JavaScript SOAP Request

Posted on 2013-12-02
10
Medium Priority
?
510 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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).

705 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