C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » WCF/Webservices »

STEP BY STEP: Consuming .NET Web Service in Java (Part I)


Posted Date: 17 Feb 2004    Resource Type: Articles    Category: WCF/Webservices
Author: N.T.GopalakrishnanMember Level: Gold    
Rating: 1 out of 5Points: 10



The Hello World Sample (again!!)

Let’s take the classic example of the Hello World one. And writing this Hello World will be easy. Here is the sample code.


Imports System.Web.Services

<System.Web.Services.WebService(Namespace:="http://tempuri.org/SampleService/Service1")> _
Public Class SampleService
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function HelloWorld(ByVal Name As String) As String
Return "Wishing, " & Name & ", Hello World"
End Function
End Class


  • Please note that the “Web Services Designer Generated Code” region is not shown for brevity

    This is what the “default” web service and web method looks like.

    But this does not work for Java – Why?

    Why is it so? That is because of the WSDL produced by the above web service. When you compile and run the web service, .net emits two different types of WSDL – one is called the Literal and the other one is the SOAP RPC. While by default .net emits a SOAP Literal type of WSDL, Java (and to my knowledge other Non-MS Languages, supporting Web Services), looks for RPC type of WSDL. And since they are not compatible, they just don’t work “out of the box”.

    SOAP Literal and RPC

    Now, how can you find the difference? Have a look at the sample WSDL produced by the above web service, below:



    (To find the WSDL, type http://...../SampleService.asmx?WSDL on your web browser). Find the soapAction attribute of soap:operation element and the use attribute of soap:body element. The value in the soapAction attribute will be used in your Java code to call this Hello World method. The use=Literal tells that this WSDL is of type Literal and not RPC.

    Making your Web Service RPC Compatible

    So, what should we do to make our Web Service “RPC Compatible”? By doing some simple changes to our code. That is, to tell our web service that it should be of type RPC.

    Now, where should be make those changes? At the class level and at the method level. Along with the <System.Web.Services.WebService()> attribute above the Class declaration, you should also add the <System.Web.Services.Protocols.SoapRpcService()> attribute also. Then, along with the <WebMethod()> attribute for the actual web method, you should also add the <System.Web.Services.Protocols.SoapRpcMethod()>. The sample code is given below:


    Imports System.Web.Services


    <System.Web.Services.WebService(Namespace:="http://tempuri.org/SampleService/Service1"),
    System.Web.Services.Protocols.SoapRpcService()> _
    Public Class SampleService
    Inherits System.Web.Services.WebService

    <WebMethod(),System.Web.Services.Protocols.SoapRpcMethod()> _
    Public Function HelloWorld(ByVal Name As String) As String
    Return "Wishing, " & Name & ", Hello World"
    End Function
    End Class


    That’s it!! You have made your Web Service RPC Compatible! Now, look at the kind of WSDL produced by the web service.



    And note that the style has changed from Literal to RPC. Also note the structural changes made to the WSDL, by going through the entire WSDL for both Literal and RPC types.

    Web Services – Done, Java – Yet to…

    That’s all you need to make your web service get consumed by Java. This part of the article guided you to the steps for making it consumable by Java and the next part will concentrate on Java itself. Until I come back to you with Java code for this web service, its

    Bye! Bye!!


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    (No tags found.)

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: STEP BY STEP: Consuming Webservices through VBA (Excel or Word) - Part II
    Previous Resource: Service Oriented Architecture
    Return to Discussion Resource Index
    Post New Resource
    Category: WCF/Webservices


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use