Part 1 of this article demonstrated how to build a .NET Credit Check Web service and invoke it from a WebSphere® Studio Application Developer test server. This article describes how to build the same Web service in Application Developer and invoke it from a .NET client. For instructions on how to perform some general tasks not covered in detail in this article, see Hints and tips in Part 1.
Invoking a WebSphere Studio Application Developer Web service from a .NET client
To invoke a WebSphere Studio Application Developer (hereafter called Application Developer) Web service from a .NET client, you must add a Web Service reference to the .NET client. The Web reference is the Application Developer WSDL URL. The WSDL file (the description of the service written in XML) is the key for a client to invoke the Web service. From this WSDL, .NET can generate a Web service Proxy. The proxy acts as an intermediary between the workstation and the Internet. Client programs use the proxy to interact with the Web service. The proxy acts as a client on behalf of the user and requests a page from the server on the Internet. When the page is returned, it relates the page to the original request and forwards it to the .NET client. The Application Developer Web service runs on the Application Developer test server.
Invoking an Application Developer Web service from a .NET client involves the following steps:
- Creating an Application Developer Web service
- Installing and using a .NET client to invoke the Web service
Step 1: Creating an Application Developer Web service
You will create an example Application Developer Web service called Credit Check using provided code and invoke it from a .NET client. The .NET client is developed using provided code and acts as an input form and display page for the Web service details. The Credit Check Web service has been designed for test purposes only. Depending on which methods are called from the .NET client, the Web service can return either a simple type (a string value representing the credit score) or a complex type (an object), representing detailed information on a person.
The following is a list of prerequisite software:
- WebSphere Studio Application Developer Version 5.0
- Internet Information Services (IIS) version 5.0
- .NET Framework version 1.0 or later
- Microsoft Visual Studio .NET Professional 2002 or later
First, create a new EJB project in Application Developer.
- Open Application Developer and select Start >
Programs > IBM WebSphere Studio >
Application Developer. Specify the directory to use for
the session, for example,
D:\WSADProjects\Webservices\workspace. - Open the J2EE Perspective. Application Developer starts with an empty workspace and with the J2EE Perspective open. If it does not, Select Window => Open Perspective => J2EE.
- Create an EJB Project by selecting File => New => Other . Select EJB (on the left frame) and EJB Project (on the right frame). Click Next.
- Ensure that Create 2.0 EJB project is checked on the Select an EJB Project screen. Click Next.
- Type
CreditCheckfor the Project Name on the EJB Project screen. Accept the defaults and click Finish. - Create an EJB by clicking the EJB icon on the toolbar:
- On the Enterprise Bean Creation window, make sure CreditCheck is selected for EJB Project. Click Next.
- On the Create an Enterprise Bean window, type
CreditCheckfor Bean name andcreditCheck.ejbfor Default package. Click Next. - Accept defaults on the Enterprise Bean Details screen. Click Next on the EJB Java Class Details screen. Click Finish.
Next, create a Java package.
- Switch to the J2EE Navigator and click on the J2EE Navigator Tab (Beside the J2EE Hierarchy Tab).
- Expand the CreditCheck EJB project by right-clicking on the folder
ejbModule. - Select New => Package.
Figure 1. Creating a new package
- Type
creditCheck.javabeanas the package name and click Finish. Create Java classes within the package. These Java classes are the Person, Address, Name and Complex Person objects. - Right-click on the
creditCheck.javabeanpackage just created and select New => Class. TypePersonfor the Name field and click Finish. - Double-click the
Person.javaclass (it should be insidecreditCheck.javabean) and delete all its contents. - Copy and paste the contents of
Person.txtfrom theDiskBfolder of the.zipfile into it. - Create three more Java classes called
Address,Name, andComplexPerson. - Double-click the
Address.javaclass (it should be insidecreditCheck.javabean) and delete all its contents. - Copy and paste the contents of
Address.txtfile from theDiskBfolder into it. - Double-click the
Name.javaclass (it should be insidecreditCheck.javabean) and delete all its contents. - Copy and paste the contents of
Name.txtfile from theDiskBfolder into it. - Double-click the
ComplexPerson.javaclass (it should be insidecreditCheck.javabean) and delete all its contents. - Copy and paste the contents of
ComplexPerson.txtfrom theDiskBfolder into it. - Click Close and Save to save all the classes.
- If
creditCheck.ejbis not already expanded, expand it by clicking on the plus sign (+) beside it. - Double-click
CreditCheckBean.java. Scroll to the bottom and place the cursor just after theejbRemovemethod:public void ejbRemove() { }
- Press Enter twice to create space between the last method and the code you are about to copy in.
- Copy and paste the contents of
CreditCheckEJB.txt. The code you have just copied is the Web service. - Right-click anywhere in the code and select Source => Organize Imports.
- Select
creditCheck.javabean.Nameby double-clicking on it from the list of imports, thencreditCheck.javabean.Address,creditCheck.javabean.Person,creditCheck.javabean.ComplexPerson, respectively. - Click Close and Save.
Next, create a Web Project by doing the following:
- Select File => New => Other. Select Web (on the left frame) and WebProject (on the right frame). Click Next.
- Type
CreditCheckWebfor the Project name and click Finish. - Right-click
CreditCheckWeband select Properties. Click on Java Build Path, Projects Tab and check CreditCheck. Click OK.
Next, set preferences by doing the following:
- Select Window => Preferences.
- If you access the Internet through a proxy, select Internet and check Enable proxy and type in the Proxy host and Proxy port. For details on how to check proxy settings, see Hints and tips in Part 1. Click Apply.
- Expand Web Services and select Code Generation.
- In the Code Generation Tab (right frame), check Use inline schema and click Apply. Click OK.
Deploy the CreditCheckBean as a Web service by doing the following:
- Right-click CreditCheckBean.java (it
should be in
CreditCheck/ejbModule/creditCheck.ejb). - Select Web services => Deploy as Web service.
- On the "Deploy as Web service" window, make sure that the WebProject
is
CreditCheckWeb. If it is not, select it from the menu. - Accept other defaults and click Next.
- On the "Configure the Java Bean as Web service" screen, select a Java
bean. Accept the default Bean (
creditCheck.ejb.CreditCheckBean) and click Next. - Accept the defaults on the "Specify methods to display" screen and
click Next. Click Finish. The WSDL files for the Web
services are in the directory
CreditCheckWeb/WebContent/wsdl/creditCheck/ejb.
To use the Web service in an environment outside of Application Developer, you must make a few changes to the WSDL. Amend the WSDL by doing the following:
- Open the
CreditCheckBeanServiceWSDL file by double-clickingCreditCheckBeanService.wsdl. - Click the Source Tab to view the WSDL code.
- Change the value of the <import location> element from
CreditCheckBeanBinding.wsdltohttp://machinename:port/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanBinding.wsdl
- Change the value of the <soap:address location> element
from
http://localhost/CreditCheckWeb/servlet/rpcroutertohttp://machinename/CreditCheckWeb/servlet/rpcrouter. This lets your .NET client machine locate the Application Developer Web service machine to invoke the Web service.Figure 2. The CreditCheckBeanService.wsdl source code
<?xml version="1.0" encoding="UTF-8"?> <definitions name="CreditCheckBeanService" targetNamespace="http://ejb.creditCheck.wsdl/CreditCheckBeanService/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:binding="http://ejb.creditCheck.wsdl/CreditCheckBeanBinding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ejb.creditCheck.wsdl/CreditCheckBeanService/"> <import location= "http://ibmws2:9080/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanBinding.wsdl" namespace="http://ejb.creditCheck.wsdl/CreditCheckBeanBinding/"/> <service name="CreditCheckBeanService"> <port binding="binding:CreditCheckBeanBinding" name="CreditCheckBeanPort"> <soap:address location="http://ibmws2:9080/CreditCheckWeb/servlet/rpcrouter"/> </port> </service> </definitions>
- Click Close and Save.
Run the project on the server by doing the following:
- Right-click the
CreditCheckBeanService.wsdland select Run on server. - Check the WSDL URL for the service by typing it into a browser. It
is:
http://machinename:port/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanService.wsdl
The browser should contain the WSDL as shown in Figure 3.Figure 3. The CreditCheckBeanService.wsdl file
<?xml version="1.0" encoding="UTF-8" ?> - <definitions name="CreditCheckBeanService" targetNamespace="http://ejb.creditCheck.wsdl/CreditCheckBeanService/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:binding="http://ejb.creditCheck.wsdl/CreditCheckBeanBinding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ejb.creditCheck.wsdl/CreditCheckBeanService/"> <import location= "http://ibmws2:9080/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanBinding.wsdl" namespace="http://ejb.creditCheck.wsdl/CreditCheckBeanBinding/" /> - <service name="CreditCheckBeanService"> - <port binding="binding:CreditCheckBeanBinding" name="CreditCheckBeanPort"> <soap:address location="http://ibmws2:9080/CreditCheckWeb/servlet/rpcrouter" /> </port> </service> </definitions>
- Check the WSDL URL for the binding by typing into the browser:
http://machinename:port/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanBinding.wsdl
The browser should contain the WSDL as shown in Figure 4.Figure 4. The CreditCheckBeanBinding.wsdl file
<?xml version="1.0" encoding="UTF-8" ?> - <definitions name="CreditCheckBeanBinding" targetNamespace="http://ejb.creditCheck.wsdl/CreditCheckBeanBinding/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:interface="http://ejb.creditCheck.wsdl/CreditCheckBean/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ejb.creditCheck.wsdl/CreditCheckBeanBinding/"> <import location="CreditCheckBean.wsdl" namespace="http://ejb.creditCheck.wsdl/CreditCheckBean/" /> - <binding name="CreditCheckBeanBinding" type="interface:CreditCheckBean"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> - <operation name="returnMComplexQuote"> <soap:operation soapAction="" style="rpc" /> - <input name="returnMComplexQuoteRequest"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/creditCheck.ejb.CreditCheckBean" parts="title surname forename houseNo address1 address2 country postcode policyID" use="encoded" /> </input> - <output name="returnMComplexQuoteResponse"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/creditCheck.ejb.CreditCheckBean" use="encoded" /> </output> </operation> - <operation name="ejbActivate"> <soap:operation soapAction="" style="rpc" /> - <input name="ejbActivateRequest"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/creditCheck.ejb.CreditCheckBean" use="encoded" /> </input> - <output name="ejbActivateResponse"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/creditCheck.ejb.CreditCheckBean" use="encoded" /> </output> </operation>
The WSDL used in .NET is the Web service WSDL. It is:http://machinename:port/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanService.wsdl
Step 2: Installing and using a .NET Client to invoke the Web service
Create a .NET client from files provided in the downloadable zip file provided at the bottom of Part 1. The client is used to invoke the Application Developer Web service. It displays results from the service depending on what methods are called. To create the client:
- Copy the provided .NET client onto your workstation.
- Open Visual Studio Projects. The client code should be in a folder
called
MyDocuments. - Copy and paste the contents of the folder
CreditCheckApp2fromDiskE/VisualStudioProjectsof the.zipfile into it. - Open
C:/inetpub/wwwroot/and copy and paste the folderCreditCheckApp2from the folderDiskE/IIS Projectsinto it.
Configure the project to run the Web service from your machine as follows:
- Open
MyDocuments/Visual Studio Projects/CreditCheckApp2and right-click CreditCheckApp2. - Select Open With => Notepad.
- Change the machine name and port number in the URL to your machine
name and port number. It should change to the following:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditCheckApp2", "http://machinename:port/CreditCheckApp2/CreditCheckApp2.csproj", "{959CE1F1-384D-41C1-8426-AFC9D771A17E}"
For example:
Microsoft Visual Studio Solution File, Format Version 7.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditCheckApp", "http://dotNet:8040/CreditCheckApp/CreditCheckApp.csproj", "{19E2BD82-A247-482C-806F-7D672D9FEA7F}" EndProject
- Open the project in Visual Studio .NET by double-clicking
CreditCheckApp2:
- Delete the existing Web reference
serviceRefby right-clicking on it and selecting Delete.
Add the Web reference to the Web service you created in Application Developer by doing the following:
- Select Project => Add a Web Reference.
Figure 5. Adding a Web Reference
- Type the URL for the Application Developer Web service you created.
It is:
http://machinename:port/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanService.wsdl
Figure 6. Entering the URL for the Web service
- Click on the green curved arrow and click Add Reference.
- Rename the Web reference by right-clicking on the reference (it
appears as the machine name on which the service resides). Select
Rename and type
serviceRef.
Build and run the project by doing the following:
- Select Build => Build Solution from the tool bar.
- Select Debug => Start without debugging. An
Internet Explorer page opens with an Introduction Page.
Figure 7. Introduction page for the Web service
- Follow the online instructions to test the Web service.
The Web service input forms and expected results are shown in Figures 8 through 13.
Figure 8. Input form for simple quote
For the returnSimpleQuote method, the result is
a string value indicating whether the credit check result is a pass or
fail.
Figure 9. Result of simple quote
Figure 10. Input form for complex quote
The result of the returnComplexQuote method is
a person object, which displays
person.creditScore and
person.creditWeight. All the person properties
may be displayed.
Figure 11. Result of complex quote
Figure 12. Input form for more complex quote
The result of the returnMComplexQuote method is
a person object, which displays:
person.name.titleperson.name.firstnameperson.name.lastnameperson.address.house numberperson.address.address1person.address.address2person.address.postcodeperson.address.countryperson.creditScoreperson.creditWeight
All the person properties may be displayed.
Figure 13. Result of more complex quote
Interoperability is the key to the success of Web services. Web services clients developed in WebSphere Studio Application Developer can successfully invoke .NET C# Web services. Similarly, .NET Web services clients can successfully invoke Application Developer Web services. Both simple and complex Web services can interoperate regardless of the technology used (J2EE or .NET) and the server infrastructure (WebSphere Application Server or IIS) on which they reside.
Part 1 demonstrated invoking a .NET Web service (deployed on Microsoft IIS) from an Application Developer client. This article demonstrates invoking an Application Developer Web service (deployed on WebSphere Application Server) from a .NET client.
Acknowledgments
The author would like to thank Kieran Scott for his help at the early stages of this project and for providing a title for this article. Kieran Scott is a Solution Test Specialist working for WebSphere Platform System House in the IBM Hursley Solution Test team. He works on developing solutions to test interoperability between IBM products, specializing in Web services. You can reach Kieran at kierans@uk.ibm.com.
-
Web services interoperability between the WebSphere and .NET platforms
-
How IBM WebSphere Studio Application Developer Compares with Microsoft Visual Studio .NET - Conceptual Differences
Ope-Oluwa Soyannwo is a Web services tester at IBM Hursley Solution Test Department, IBM Hursley. She works on testing interoperability between WebSphere products and Microsoft Visual Studio .NET. You can reach Ope at soyannwo@uk.ibm.com .





