Solved

Need help with JavaScript SOAP Request

Posted on 2013-12-02
10
485 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript reference in ExcelWebAddIn Project 2 33
hide and show spans from dropdown selection 3 37
center text in div with CSS3 2 30
SSL unsecure page mystery 17 46
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

734 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