Step 2: Test the request

Once the automatically generated JavaScript code has been saved, write a calling JavaScript to execute the Web Service. The following is a simple example code for IncidentManagement record retrieval:

function RetrieveIncident(incident_id)
{
	var IncMgmtSvc = new system.library.IncidentManagement.
IncidentManagement();
	IncMgmtSvc.user="falcon"

	var retrieveReq = new system.library.IncidentManagement.
RetrieveIncidentRequest();

	retrieveReq.model.keys.IncidentID.setValue(incident_id);

	try
	{
		 var retrieveResp = IncMgmtSvc.invoke(retrieveReq);
	 	if ( retrieveResp.isFault() )
		{
			throw( "SOAP Fault: " + retrieveResp.
faultstring.getValue() );
		}
		return retrieveResp.model.instance;
	}
	catch( err )
	{
	  return( "Error! " + err );
	}
}

retVal=RetrieveIncident("IM1001");

print("Testing the result " + retVal.IncidentID.getValue())
        
  1. To test the request, enter debughttp in the sm.ini file and restart the server and client.
  2. If the file http.log exists in the server’s RUN directory, remove it or remove its contents so that there will be a fresh file to read.
  3. Go into the calling JavaScript and click Execute. You will most likely get an error message because the Web service you are trying to reach is not available.
  4. After the execution is complete, open the http.log file and search for the following:

    POST /sc62server/ws HTTP/1.1
    accept: application/fastinfoset, text/xml, text/html,
    image/gif, image/jpeg, *; q=.2, */*; q=.2
    authorization: Basic ZmFsY29uOg==
    soapaction: Retrieve
    connection: Close
    content-type: text/xml; charset=utf-8
    content-length: 841
    cache-control: no-cache
    pragma: no-cache
    user-agent: Java/1.5.0_08
    host: <server>:<port>
    
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/
    envelope/" 
     xmlns:ns0="http://servername.port_number/SM/7/service_name.wsdl"
     xmlns:ns1="http://schemas.xmlsoap.org/wsdl/http/"   
     xmlns:ns2="http://schemas.xmlsoap.org/wsdl/mime/"
     xmlns:ns3="http://servicecenter.peregrine.com/PWS 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-
     instance"><soap:Body><ns3:RetrieveIncidentRequest attachmentData=
     "false" attachmentInfo="false" 
     ignoreEmptyElements="true">
     <ns3:model><ns3:keys><ns3:IncidentID mandatory="false"
      readonly="false" type="String">IM1001</ns3:IncidentID>
    </ns3:keys><ns3:instance><ns3:IncidentDescription
     type="Array"/><ns3:Resolution type="Array"/>
    <ns3:JournalUpdates
      type="Array"/>
    <ns3:Solution type="Array"/></ns3:instance>
    </ns3:model></ns3:RetrieveIncidentRequest></soap:Body></soap:Envelope>
    
    HTTP/1.1 200
    Set-Cookie: JSESSIONID=0405ED23EFF6C9A3874F77796FE4210D;
    Path=/sc62server
    Connection: close
    Connection: close
    Content-Type: application/fastinfoset;charset=utf-8
    Content-Length: 1323
    Date: Wed, 04 Jun 2008 22:09:56 GMT
    Connection: close
    Connection: closeSet-Cookie: SessionId=16.95.106.150:3487;
    Version=1
  5. You can copy the bold area into an XML editor such as Altova® XMLSpy® and check whether it is correct XML. If it is, then the request is deemed to be successful (which does not necessarily mean that it will return data).

Another method to check the request and response is to run the request through a tool such as tcpmon. To do so, start tcpmon, enter the server name and port of the receiving Web service and connect the invoking JavaScript to tcpmon. Both the request and the response are visible in the tcpmon screen and can be analyzed in an XML editor as well.