Creating web service clients
When you publish an AR System web service, a WSDL document that describes the web service is created in Developer Studio. A web service client must be created to interact with this web service. Many environments can be used to create web service clients. Most have tools that automatically generate code to invoke a web service, given the WSDL. Apache AXIS, a third-party library, is installed with the Mid Tier for this purpose, but you can use other web service frameworks as well.
Popular environments for writing web service clients include these:
Apache AXIS—In AXIS, run WSDL2java from the command line with the WSDL URL as a command-line parameter. The autogenerated code is a class that has methods that correspond exactly to the operations you created in the web service. Each method has input and output parameters corresponding to the mappings you created. To invoke the web service, instantiate the class and invoke a method with the correct parameters. For more information, see http://ws.apache.org/axis/java/user-guide.html and http://ws.apache.org/axis2/1_2/quickstartguide.html.
- JAX-WS—In JAX-WS, run wsimport from the command line with the WSDL URL as a command-line parameter. The autogenerated code contains the necessary class to invoke any operation on the web service.
Microsoft.NET—In Microsoft.NET Visual Studio, autogenerate the invocation code by adding a web reference. When prompted for a URL, enter your WSDL URL. For more information, see https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/w3h45ebk(v=vs.100)
To create a .NET web service client
- Create a basic web service named SimpleWebService.
Install Microsoft .NET Runtime and Visual Studio .NET 7.0 from https://visualstudio.microsoft.com/.
This information is provided as a convenience only. For instructions about installing and using Microsoft products, see the appropriate Microsoft documentation at https://docs.microsoft.com/en-us/.
- Open Visual Studio .NET 7.0.
- Select File > New > Project.
- From the set of available project types, select Visual C# Projects.
- Select Console Application from Templates.
- In the Name field, enter WSClient.
- In the Location field, enter the directory name in which you want to store the project files. (for example, C:\temp).
- Click OK.
- Select View > Solution Explorer.
- In Solution Explorer, right-click WSClient and select Add Web Reference.
In the Address bar, enter the URL for WSDL (for example, http://<midtierServer>/arsys/WSDL/<arServer>/SimpleWebService, as created in the Creating-a-basic-web-service procedure).
For information about WSDL, see http://www.w3.org/TR/wsdl.- Enter the user name and password, and click Login (this is needed only if public access is not provided to the web service that you created).
- Click Add Reference.
- Select Project > Show All Files.
- In Solution Explorer, under Web References, right-click SimpleWebService.cs and select View Code.
SimpleWebService.cs is the proxy class generated for making requests to your web service. - Click the Class1.cs tab.
- After the using System statement, enter the following statement on a separate line:
using WSClient.<midtierServer>; Enter the following code in the Main method (after the //TODO... statement):
// create a proxy object to make web service requests
SimpleWebService proxy = new SimpleWebService();
// set up authentication info
AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.userName = "Demo"; // give a valid AR user name
authInfo.password = ""; // give a valid password
proxy.AuthenticationInfoValue = authInfo;
// declare variables
String Assigned_To;
String Short_Description;
StatusType Status;
String Submitter;
String Request_ID;
// supply values for creating an entry using OpCreate
Assigned_To = "Frank";
Short_Description = "Testing web service";
Status = StatusType.New;
Submitter = "Joe";
// make web service request to create an entry and make changes to this code as per the operation names defined in your web service
Request_ID = proxy.OpCreate(Assigned_To, Short_Description, Status, Submitter);
Console.WriteLine("Successfully created a request with id: " + Request_ID);
// declare additional variables for get operation
DateTime Create_Date;
String Last_Modified_By;
DateTime Modified_Date;
String Status_History;
// make web service request to get the entry that was created above
Assigned_To = proxy.OpGet(ref Request_ID, out Create_Date, out Last_Modified_By, out Modified_Date,
out Short_Description, out Status, out Status_History, out Submitter);
Console.WriteLine();
Console.WriteLine("Following values have been returned by OpGet");
Console.WriteLine();
Console.WriteLine("Request_ID : " + Request_ID);
Console.WriteLine("Create_Date : " + Create_Date);
Console.WriteLine("Last_Modified_By : " + Last_Modified_By);
Console.WriteLine("Modified_Date : " + Modified_Date);
Console.WriteLine("Short_Description : " + Short_Description);
Console.WriteLine("Status : " + Status);
Console.WriteLine("Status_History : " + Status_History);
Console.WriteLine("Submitter : " + Submitter);
Console.WriteLine("Assigned_To : " + Assigned_To);- Select Build > Rebuild All.
- Change directory to C:\temp\WSClient\bin\Debug.
- Enter WSClient.exe at the command prompt to run the client.
To create an Apache Axis web service client
- Create a basic web service named SimpleWebService.
- Install JDK 1.8.45 or later.
- Ensure that java and javac commands are included in the PATH.
Install Apache Axis 1.x from http://xml.apache.org/axis.
Install Xerces2 Java Parser 2.2.0 from http://xml.apache.org/xerces2-j/index.html.
Install JavaServer Pages 1.2 class files from https://www.oracle.com/java/technologies/.
Set CLASSPATH to include Axis and Xerces JAR files as follows:
set AXIS_DIR=<axisInstallDir>
set AXIS_LIB_DIR=%AXIS_DIR%\lib
set XERCES_DIR=<xercesInstallDir>
set JSP_DIR=<jspInstallDir>
set CLASSPATH=.;%AXIS_LIB_DIR%\axis.jar;%AXIS_LIB_DIR%\saaj.jar;%AXIS_LIB_DIR%\arlogger-9.1.11-SNAPSHOT.jar;%AXIS_LIB_DIR%\wsdl4j.jar;%AXIS_LIB_DIR%\commons-discovery.jar;%AXIS_LIB_DIR%\jaxrpc.jar;%AXIS_LIB_DIR%\commons-logging.jar;%XERCES_DIR%\xercesImpl.jar;%XERCES_DIR%\xmlParserAPIs.jar; %JSP_DIR%\servlet.jar- Create a directory for building an Axis web service client (for example, C:\temp\axisclient).
- Change directory to C:\temp\axisclient.
At the command prompt, enter the following command:
java org.apache.axis.wsdl.WSDL2Java -W -p ARWSClient http://<midTierServer>/arsys/WSDL/<arServer>/SimpleWebServiceThis command generates proxy classes for writing the client program.
- Create a directory for storing the class files (for example, C:\temp\axisclient\classes).
- Change directory to ARWSClient.
Create a new file called TestClient.java and add the following lines of code:
/**
* TestClient.java
*
*/
package ARWSClient;
import javax.xml.rpc.holders.StringHolder;
import javax.xml.rpc.holders.CalendarHolder;
public class TestClient {
public static void main(String args[]) throws Exception
{
SimpleWebServicePortType binding;
binding = new SimpleWebServiceServiceLocator().getSimpleWebServiceSoap();
// declare variables
CreateInputMap createInput = new CreateInputMap();
// supply values for creating an entry using OpCreate
createInput.setAssigned_To("Frank");
createInput.setShort_Description("Testing Axis Client");
createInput.setStatus(StatusType.New);
createInput.setSubmitter("Joe");
// make web service request to create an entry
CreateOutputMap createOuput = binding.opCreate(createInput);
System.out.println("Successfully created a request with id: " + createOuput.getRequest_ID());
// declare additional variables for get operation
GetInputMap getInput = new GetInputMap();
getInput.setRequest_ID(createOuput.getRequest_ID());
ARWSClient.GetOutputMap getOutput;
getOutput = binding.opGet(getInput);
System.out.println();
System.out.println("Following values have been returned by OpGet");
System.out.println();
System.out.println("Request_ID : " + getOutput.getRequest_ID());
System.out.println("Assigned_To : " + getOutput.getAssigned_To());
System.out.println("Create_Date : " + getOutput.getCreate_Date().getTime());
System.out.println("Last_Modified_By : " + getOutput.getLast_Modified_By());
System.out.println("Modified_Date : " + getOutput.getModified_Date().getTime());
System.out.println("Short_Description : " + getOutput.getShort_Description());
System.out.println("Status : " + getOutput.getStatus());
System.out.println("Status_History : " + getOutput.getStatus_History());
System.out.println("Submitter : " + getOutput.getSubmitter());
}
}- Enter the following command:
javac -d ..\classes *.java - Open the BMC Remedy Mid Tier Configuration Tool, and under WebService Settings, enter an anonymous user name (for example, Demo), leaving the password blank.
- Change directory to ..\classes.
- Enter the following command to run the client:
java ARWSClient.TestClient