calling Java services from .Net
I would like to know if anyone has any experience calling Java services from .net and any available code samples?
I would like to know if anyone has any experience calling Java services from .net and any available code samples?
Use following Client Code Imports
Public
Class Form1 Inherits System.Windows.Forms.Form#
Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer.InitializeComponent()
'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Thencomponents.Dispose()
End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(104, 136) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "Call WS" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub#
End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim pr As New Proxy Dim str As String = pr.getHi("Smith")MsgBox(str)
Catch ex As InvalidCastException End Try End SubEnd
ClassImports
SystemImports
System.DiagnosticsImports
System.Web.ServicesImports
System.Web.Services.ProtocolsImports
System.Xml.Serialization'
'This source code was auto-generated by wsdl, Version=1.0.2914.16.
'
<System.Web.Services.WebServiceBindingAttribute(Name:="TestCommonSrvcSoap", [Namespace]:="urn:AddressFetcher")> _
Public
Class Proxy Inherits System.Web.Services.Protocols.SoapHttpClientProtocol<System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New() MyBase.New() Me.Url = "http://localhost:8080/soap/servlet/rpcrouter" End Sub <System.Diagnostics.DebuggerStepThroughAttribute(), _System.Web.Services.Protocols.SoapRpcMethodAttribute()> _
Public Function getHi(ByVal strname As String) As String Dim results() As Object = Me.Invoke("getHi", New Object() {strname}) Return CType(results(0), String) End Function<System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Function BegingetHi(ByVal strname As String, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult Return Me.BeginInvoke("getHi", New Object() {strname}, callback, asyncState) End Function<System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Function EndgetHi(ByVal asyncResult As System.IAsyncResult) As String Dim results() As Object = Me.EndInvoke(asyncResult) Return CType(results(0), String) End FunctionEnd
Class Use following JAVA Class (Web Service) and deploy on Tomcat Server as mentioned in above URL.import java.util.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.apache.soap.util.xml.*;
/**
* See \samples\addressbook\readme for info.
*
* @author Matthew J. Duftler (duftler@us.ibm.com)
*/
public class AddressBook
{
public String getHi(String name)
{
return "Hi " + name;
}
}
You will need to a setup as mentioned in above URL . This will require you to download some packages from SUN Website.
Regards,
Kalpesh Vora
You use WSDL.exe to generate proxy code like this from the SDK command prompt:
wsdl.exe [web service URL]
Daniel Roth