ÓÃJavaµ÷ÓÃC# µÄWebService½Ó¿Ú ÏÂÔØ±¾ÎÄ

ÓÃJavaµ÷ÓÃC# µÄWebService½Ó¿Ú

ÕâÊÇÒ»¸öÓÃJavaµ÷ÓÃC#°æWebService½Ó¿ÚµÄÀý×Ó£º C#½Ó¿Ú£º using System; using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols; using System.Web.Services.Description;

[WebService(Namespace = \[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService {

public Service () ... {

// Èç¹ûʹÓÃÉè¼ÆµÄ×é¼þ£¬ÇëÈ¡Ïû×¢ÊÍÒÔÏÂÐÐ // InitializeComponent(); }

[SoapRpcMethod(Action = \http://www.tangs.com/Add \, RequestNamespace = \

http://www.tangs.com/T

\

, ResponseNamespace

=

\

http://www.tangs.com/T

\= SoapBindingUse.Literal)]

[WebMethod]

public int Add( int a, int b) ... {

return a + b; }

[SoapRpcMethod(Action = \http://www.tangs.com/Hello \, RequestNamespace = \

http://www.tangs.com/T

\

, ResponseNamespace

=

\

http://www.tangs.com/T

\= SoapBindingUse.Literal)]

[WebMethod]

public String HelloWorld() ... {

return \ } } ...

Javaµ÷ÓÃÕâ¸öWebserviceÖеÄAdd·½·¨ºÍHelloWorld·½·¨£º 1.Óвη½·¨£ºAdd

public static void addTest() { try ... { Integer i = 1 ; Integer j = 2 ;

// WebService URL

String service_url = \

Service service = new Service(); Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(service_url));

// ÉèÖÃÒªµ÷Óõķ½·¨

call.setOperationName( new QName( \\

// ¸Ã·½·¨ÐèÒªµÄ²ÎÊý

call.addParameter( \ javax.xml.rpc.ParameterMode.IN);

call.addParameter( \ javax.xml.rpc.ParameterMode.IN);

// ·½·¨µÄ·µ»ØÖµÀàÐÍ

call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);

call.setUseSOAPAction( true );

call.setSOAPActionURI( \

// µ÷Óø÷½·¨

Integer res = (Integer)call.invoke( new Object[] ... { i, j } );

System.out.println( \\ + res.toString());

} catch (Exception e) ... { System.err.println(e); } }

...

ÔËÐУ¬½á¹û·µ»Ø£ºResult£º3 2.Î޲η½·¨£ºHelloWorld

public static void helloTest() { try ... {

String endpoint = \ Service service = new Service(); Call call = (Call) service.createCall();