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!!