Java is called with .NET web services

zhaozj2021-02-17  33

Java is called with .NET web services

One: Introduction

This article describes the techniques for the Web Services developed by Java and .NET. This article includes two parts, the first part describes how to use .NET to make client call Java Written Web Services, the second part introduces how to use Java to do client calls .NET development web services.

Second: Tools for project needs

Windows2000 Server (IIS)

JBuilder9.0 (with Tomcat, Axis)

JDK1.4 Java Web Services Develop

VS.NET 2003

Remarks: If there is no JBuilder, you need to download the development pack of Tomcat4.1 and AXIS yourself, and do the appropriate configuration. Due to many such articles on the Internet, it will not explain it.

Three: Use .NET to make a client calling Java WEB SERVICES

1. Generate a Java Web SERVICES

It is very simple to use JBuilder to generate a web service, I am doing it in accordance with its help, just step by step.

Going it out. The specific path is developing Web Services -> Tutorials: Web Services (Axis) -> CREANG A Simple Web SERVICES

2. Publish this web services and get it WSDL

After the Web Services is well, F9 runs this project. Then, click View to browse an existing web service, click the bean1's WSDL connection, we can see its WSDL description in your browser. Copy the WSDL address in the browser address bar to prepare for the next step using .NET development client call.

3. Generate a .NET client with vs.net

New project (Winform, ASP.NET can be used), I am using an ASP.NET project here. Place a text input box on the start page to display the result of calling Web Services, place a button, used to click Call Web Services. Then, select the Add Web reference, copy the WSDL address you just obtained in the WSDL column, the name of the web reference Enter JavaService, click the Add Reference button. At this point, we can see this web reference in the Solution Explore of VS.NET.

Enter the following code in the click event:

JavaService.bean1 bean = new javaservice.bean1 ();

TextBox1.text = bean.getsample.tostring ();

In this way, one .NET client is completed, test, work normally, OK.

Four: Use Java to do the client call .NET Write Web Services

With the success of the above, I thought I used Java to do client calls and a very easy thing, but the actual situation but I spent two days before I realized it.

1. Use VS.NET to create an ASP Web Services project, add a web service, named Sumservice.asmx. Added a Web Method, the code is as follows:

[WebMethod]

Public int INTADD (Int A, INT B)

{

RETURN A B;

}

Then run it and use IE to test success.

2. Open JBuilder9.0, create a new project, add a Java class, named TestNetService, enter the following code: package mywebservicejavaclient;

Import java.util.date;

Import java.text.dateFormat;

Import java.util.date;

Import java.text.dateFormat;

Import org.apache.axis.client.call;

Import org.apache.axis.client.service;

Import javax.xml.namespace.qname;

Import java.lang.integer;

Import javax.xml.rpc.parametermode;

/ **

*

Title:

*

description:

*

Copyright: Copyright (C) 2004

*

company:

* @Author NOT Attributable

* @version 1.0

* /

Public class testnetService {

Public TestNetService () {

}

Public static void main (String [] args) {

Try {

Integer i = new integer (1);

Integer J = New Integer (2);

String endpoint = "http://localhost/myservices/webservicetest/sumservice.asmx";

Service service = new service ();

Call call = (call) service.createcall ();

Call.SettargetendPointdaddress (New Java.net.URL (Endpoint));

Call.SetoperationName (New QName ("http://www.my.com/su", "intadd"));

Call.addparameter ("a", org.apache.axis.encoding.xmltype.xsd_date, javax.xml.rpc.parametermode.in);

Call.addparameter ("B", org.apache.axis.encoding.xmltype.xsd_date, javax.xml.rpc.parameterMode.in);

Call.setReturntype (Org.Apache.axis.Encoding.xmltype.xsd_int);

Call.setusesoaPAction (TRUE);

Call.SetsoApactionuri ("http://www.my.com/rpc");

Integer K = (Integer) Call.Invoke (New Object [] {i, j});

System.out.println ("Result IS" K.ToString () ".");

}

Catch (Exception E) {system.err.println (e.tostring ());}

}

}

Run the above Java client program, you will find that the system will throw a soapaction exception. Strange, how can it be wrong? I thought that the ASP Web Services I develop did not specify soapAction, so add the following code in [Web method] in Sumservice.asmx: [SOAPRPCMethod (action = "http://www.my.com/rpc", requestnamespace = "http://www.my.com/su", responsenamespace = "http://www.my.com/su")]

After re-compiling the ASP Web Services, the Java program is executed, and the correct result 3 will be found.

In this way, Web Services generated by Java .NET is also initially completed, it seems to be not very complicated. In fact, in actual work, I didn't find a good code example in the Internet. All relying on JBuilder and Axis help, but always prompt to find the corresponding soapaction. In fact, I can see that soapaction in the IE browser after running the ASP Web Services. I tried to copy the default SOAPAction into the Java code, but the Java client still throws the same exception, this is also confused.

Five: Summary

After two days of experiment, it is finally clarified by Web Services. Net and Java interoperability. Of course, there is a matter of attention:

1. When providing Web Services, try to use the variable types supported in XML Schema to do parameters. If the DataSet in .NET is used, it will be a disaster for Java, of course, theoretically analyzed. However, from the efficiency angle, there is always a serialization and reverse sequence of problems during the exchange information of Web Services and client. If you use DataSet, the system needs to serialize it, which will be a very resource process. The type of String will be simply available.

2. If SOAP Header is used, for example, Microsoft's WSE technology is used, and the mutual communication between them requires special processing. See:

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwse/html/wsejavainterop.asp

This article reference:

Http://forum.java.sun.com/thread.jsp?thread=386360&ster = 331&imentage=1661636

Since I have limited level, please pay more attention.

Email: dlut_chen@hotmail.com

转载请注明原文地址:https://www.9cbs.com/read-30529.html

New Post(0)