Connecting to a secure Web service

If you are consuming a secure Web service that requires mutual authentication from Service Manager application using Javascript and WSDL2JS, follow these steps:.

If you are consuming an SSL-protected Web service using Javascript in SM 7x, which uses java.xml.soap.SOAPConnection to send the request, the SSL configuration is done using Java key stores. Refer to the documentation for the list of sm.ini parameters required for SSL configuration.

When you consume a secure Web service or Web site from JavaScript all you need to do is use an https:// URL. There are no facilities for configuring SSL in WSDL2JS or in your script. The SSL communication that is initiated by the WSDL2JS-generated code relies on the SSL configuration that is in place for the server itself. The Service Manager server’s server certificate in effect becomes the client certificate for the outbound request.

To supply a Basic Authorization header when consuming a Web service using JavaScript generated by WSDL2JS, basic authentication is supplied automatically if you supply userid and password values on the service object generated by WSDL2JS as shown in the below example:

	var service = new system.library.IncidentManagement.
	IncidentManagement();

	service.user = "falcon";
	service.password = "";
	...

If on the other hand, you are coding a REST-style GET directly in your script, you need to code it manually, because you have to code the HTTP request yourself. Add the following style code in the JavaScript to perform this:

// HTTP GET example with Basic Auth header

    var headers = new Array();

    try
    {
      if ( result.userid != undefined )
      {
        var authHeader = new Header();
           
        authHeader.name = "Authorization";
        authHeader.value = "Basic " + base64Encode
	( result.userid + ":" + result.password ); 
      
        headers.push( authHeader );  
      }
            
   strWSDLsrc = doHTTPRequest( "GET", wsdlURL, headers, null,
 	10, 10, 10 );
 }
    catch( e )
    {     
      print( "WSDL request failed with exception " + e );
      ...
    }