Skip to main content

IBM WebSphere Studio and Microsoft .NET Working Together -- Part 2

Invoking a WebSphere Studio Web Service from a .NET Client

Ope-Oluwa Soyannwo (soyannwo@uk.ibm.com), Software Engineer, Hursley Solution Test, IBM Hursley
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 .

Summary:  This two-part article describes how to build Web services in both IBM WebSphere Studio and Microsoft Visual Studio .NET. It demonstrates the interoperability between WebSphere Studio and .NET. It also provides detailed deployment instructions for invoking Web services that return objects and nested objects. Part 1 describes how to invoke .NET Web services deployed in IIS from J2EE clients developed with WebSphere Studio. Part 2 describes how to invoke J2EE Web services deployed in the WebSphere Studio Test Environment from .NET clients developed with Visual Studio .NET.

Date:  27 Aug 2003
Level:  Introductory
Activity:  296 views
Comments:  

Introduction

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:

  1. Creating an Application Developer Web service
  2. 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.

  1. 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 .
  2. 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.
  3. Create an EJB Project by selecting File => New => Other . Select EJB (on the left frame) and EJB Project (on the right frame). Click Next.
  4. Ensure that Create 2.0 EJB project is checked on the Select an EJB Project screen. Click Next.
  5. Type CreditCheck for the Project Name on the EJB Project screen. Accept the defaults and click Finish.
  6. Create an EJB by clicking the EJB icon on the toolbar:
    EJB icon
  7. On the Enterprise Bean Creation window, make sure CreditCheck is selected for EJB Project. Click Next.
  8. On the Create an Enterprise Bean window, type CreditCheck for Bean name and creditCheck.ejb for Default package. Click Next.
  9. Accept defaults on the Enterprise Bean Details screen. Click Next on the EJB Java Class Details screen. Click Finish.

Next, create a Java package.

  1. Switch to the J2EE Navigator and click on the J2EE Navigator Tab (Beside the J2EE Hierarchy Tab).
  2. Expand the CreditCheck EJB project by right-clicking on the folder ejbModule.
  3. Select New => Package.
    Figure 1. Creating a new package
    Creating a new package
  4. Type creditCheck.javabean as the package name and click Finish. Create Java classes within the package. These Java classes are the Person, Address, Name and Complex Person objects.
  5. Right-click on the creditCheck.javabean package just created and select New => Class. Type Person for the Name field and click Finish.
  6. Double-click the Person.java class (it should be inside creditCheck.javabean) and delete all its contents.
  7. Copy and paste the contents of Person.txt from the DiskB folder of the .zip file into it.
  8. Create three more Java classes called Address, Name, and ComplexPerson.
  9. Double-click the Address.java class (it should be inside creditCheck.javabean) and delete all its contents.
  10. Copy and paste the contents of Address.txt file from the DiskB folder into it.
  11. Double-click the Name.java class (it should be inside creditCheck.javabean) and delete all its contents.
  12. Copy and paste the contents of Name.txt file from the DiskB folder into it.
  13. Double-click the ComplexPerson.java class (it should be inside creditCheck.javabean ) and delete all its contents.
  14. Copy and paste the contents of ComplexPerson.txt from the DiskB folder into it.
  15. Click Close and Save to save all the classes.
  16. If creditCheck.ejb is not already expanded, expand it by clicking on the plus sign (+) beside it.
  17. Double-click CreditCheckBean.java. Scroll to the bottom and place the cursor just after the ejbRemove method:
    public void ejbRemove() { }

  18. Press Enter twice to create space between the last method and the code you are about to copy in.
  19. Copy and paste the contents of CreditCheckEJB.txt. The code you have just copied is the Web service.
  20. Right-click anywhere in the code and select Source => Organize Imports.
  21. Select creditCheck.javabean.Name by double-clicking on it from the list of imports, then creditCheck.javabean.Address, creditCheck.javabean.Person, creditCheck.javabean.ComplexPerson, respectively.
  22. Click Close and Save.

Next, create a Web Project by doing the following:

  1. Select File => New => Other. Select Web (on the left frame) and WebProject (on the right frame). Click Next.
  2. Type CreditCheckWeb for the Project name and click Finish.
  3. Right-click CreditCheckWeb and select Properties. Click on Java Build Path, Projects Tab and check CreditCheck. Click OK.

Next, set preferences by doing the following:

  1. Select Window => Preferences.
  2. 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.
  3. Expand Web Services and select Code Generation.
  4. 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:

  1. Right-click CreditCheckBean.java (it should be in CreditCheck/ejbModule/creditCheck.ejb).
  2. Select Web services => Deploy as Web service.
  3. On the "Deploy as Web service" window, make sure that the WebProject is CreditCheckWeb. If it is not, select it from the menu.
  4. Accept other defaults and click Next.
  5. On the "Configure the Java Bean as Web service" screen, select a Java bean. Accept the default Bean (creditCheck.ejb.CreditCheckBean) and click Next.
  6. 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:

  1. Open the CreditCheckBeanService WSDL file by double-clicking CreditCheckBeanService.wsdl.
  2. Click the Source Tab to view the WSDL code.
  3. Change the value of the <import location> element from CreditCheckBeanBinding.wsdl to
    http://machinename:port/CreditCheckWeb/wsdl/creditCheck/ejb/CreditCheckBeanBinding.wsdl

  4. Change the value of the <soap:address location> element from http://localhost/CreditCheckWeb/servlet/rpcrouter to http://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>

  5. Click Close and Save.

Run the project on the server by doing the following:

  1. Right-click the CreditCheckBeanService.wsdl and select Run on server.
  2. 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>

  3. 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:

  1. Copy the provided .NET client onto your workstation.
  2. Open Visual Studio Projects. The client code should be in a folder called MyDocuments.
  3. Copy and paste the contents of the folder CreditCheckApp2 from DiskE/VisualStudioProjects of the .zip file into it.
  4. Open C:/inetpub/wwwroot/ and copy and paste the folder CreditCheckApp2 from the folder DiskE/IIS Projects into it.

Configure the project to run the Web service from your machine as follows:

  1. Open MyDocuments/Visual Studio Projects/CreditCheckApp2 and right-click CreditCheckApp2.
  2. Select Open With => Notepad.
  3. 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

  4. Open the project in Visual Studio .NET by double-clicking CreditCheckApp2:

    Icon
  5. Delete the existing Web reference serviceRef by right-clicking on it and selecting Delete.

Add the Web reference to the Web service you created in Application Developer by doing the following:

  1. Select Project => Add a Web Reference.
    Figure 5. Adding a Web Reference
    Adding a Web                             Reference
  2. 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
    Entering the URL for the Web service
  3. Click on the green curved arrow and click Add Reference.
  4. 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:

  1. Select Build => Build Solution from the tool bar.
  2. Select Debug => Start without debugging. An Internet Explorer page opens with an Introduction Page.
    Figure 7. Introduction page for the Web service
    Introduction                             page for the Web service
  3. 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
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
Result of simple                     quote

Figure 10. Input form for complex quote
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
Result of complex                     quote

Figure 12. Input form for more complex quote
Input form for more                     complex quote

The result of the returnMComplexQuote method is a person object, which displays:

  • person.name.title
  • person.name.firstname
  • person.name.lastname
  • person.address.house number
  • person.address.address1
  • person.address.address2
  • person.address.postcode
  • person.address.country
  • person.creditScore
  • person.creditWeight

All the person properties may be displayed.


Figure 13. Result of more complex quote
Result of more                     complex quote

Conclusion

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.


Resources

About the author

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 .

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=14318
ArticleTitle=IBM WebSphere Studio and Microsoft .NET Working Together -- Part 2
publish-date=08272003
author1-email=soyannwo@uk.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers