. NET call to Java implementation method

Source: Internet
Author: User
Tags soap wsdl

I. IKVM1.1 Download Configuration IKVM

1.1.1. Download Path

Http://www.ikvm.net/index.html

1.1.2. Setting the path

Unzip the Ikvm-0.42.0.3.zip and add the%ikvm_home%/bin to the path. The%ikvm_home% here refers to the IKVM home directory after decompression.

1.2 The first way: Convert the. class file directly to a. dll

Website Introduction

Http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application

Enter the command in the DOS interface and go to the directory of the Ikvm.exe application;

At the same time, the. class file to be converted (for example, the Testmain.class file) is placed in the directory and the following command is entered in DOS:

ikvmc< spaces >–target:library< Spaces >testmain.class

You can view the generated. dll files in the C:\Program files\ikvm\bin directory

Links to the program are as follows:

1.3 Second way: Convert a Java project's jar package into a. dll

C # calls Java code directly, requires Ikvmbin-0.44.0.5.zip

1. Download and unzip

2. Configure Environment variables:

Add%ikvm_home%\bin,ikvm_home as the home directory of the extracted IKVM in path. In the DOS interface, enter the "IKVM" command to test whether the configuration was successful

3. Write Java code (Java code, to be placed under the specified package, do not put under the default packages):

1 package com.xyy.csharp;
3 Import java.util.ArrayList;
4 Import java.util.List;
6 public class Testmain {
8//Get Set
9 Public list<demo1> getlists () {
Ten list<demo1> lst=new arraylist<demo1> ();
Demo1 d=new Demo1 ();
D.setid (1);
D.setname ("admin");
Demo1 d2=new Demo1 ();
D2.setid (2);
D2.setname ("sa");
Lst.add (d);
Lst.add (D2);
return LST;
21}
23//Get string
Public String getString () {
Return "I am a string";
26}
28//Get Objects
Public Demo1 GetObject () {
Demo1 demo=new Demo1 ();
Demo.setid (1);
Demo.setname ("admin");
return demo;
34}
36//Get Boolean
PNs public boolean Getboolean () {
Boolean.true return;
39}
41//On console output
public void Systemoutprint () {
System.out.println ("I am the console output statement");
44}
45}

5. To make a Java project into a jar package (Test.jar), the packaging process is described in the notes:
6. Enter the command in the DOS interface, the CD indicates the change of the current directory, and go to the directory of the Ikvm.exe application;

At the same time, put the. jar file (for example, Ikvm.jar file) into the directory, enter the command, convert the Ikvm.jar file to the Zhou.dll file:

IKVM command format: ikvmc< Space >-out:aaa.dll< spaces >bbb.jar

Where: Bbb.jar represents the. jar file to be converted, and Aaa.dll represents the file name of the. dll to be generated.

7. Create a new C # project that introduces the following three DLLs:

%IKVM_HOME%\BIN\IKVM. OpenJDK.Core.dll

%IKVM_HOME%\BIN\IKVM. Runtime.dll

%IKVM_HOME%\BIN\IKVM. Runtime.JNI.dll

Introducing the newly packaged IKVM.dll

8.

9. Output Result:

C # cannot directly receive a collection of Java returns, and there is no further study

Note: Package a Java project into a jar package process

Http://www.cnblogs.com/myCodingSky/p/3347511.html

Java Project hit jar package is divided into 2 cases:

One, the Java project does not import third-party jar packages

1. First open the project in Eclipse, right click on the project, select "Export";
2. Select Java/jar File,next;
3. Select the resources to export you can choose the project folder you want to include, some unnecessary folders do not need to put in, so as not to increase the space;
Here are a few options:
*export generated classfiles and resources means that only the generated. class files and other resource files are exported
* Export all output folders for checked projects means all folders for the selected item are exported
* Export Java source file and resouces means the exported jar package will contain your source code *.java, if you do not want to leak the source, then do not choose this
* Export refactorings for checked projects contains some of the reconstructed information files.


Select the path to the exported jar in the selectthe export destination, Next
4. On the next page, you can choose whether to export *.class files that contain warning warning or error errors. Generally, don't worry about him, Next.
5. The next page can be configured for the project. (If the project does not introduce a third-party jar package, this is the system default option for Ok,mainclass must be set to be the Main method entry class for your project)
* Generate The manifest file is the system to help us automatically generate MANIFEST.MF files, if your project does not reference other Class-path, then you can choose this.
* Use existing mainfest from workspace This is optional we can customize. MF file, formatted as above.
* Seal content to encapsulate the entire jar or the specified package packet
* Main class Here you can choose your program portal, the future packaging of the jar is your entry class execution results.
Final finish, done. ......

Second, Java project has imported third-party jar package (for example, the project has imported Sqlserver2005.jar package)

Packing is a bit more complicated at this time:

The previous 4 steps are the same as the above, but the 5th step requires selecting the Useexisting mainfest from workspace option and choosing a manifest that you created yourself. MF file, because the generate the manifest file option is selected by default, and this option does not use the third-party jar package that the project uses to penetrate into the jar package generated by the Java project.

Custom configuration file MANIFEST.MF:

First create a manifest.mf file in the root directory of the project

Next, open the file with Notepad and edit:

For example:
manifest-version:1.0
Main-class:studentmanager_test
Class-path:sqlserver2005.jar
The manifest-version refers to the version number of the program, Main-class refers to the program's Main method entry class, Slass-path specifies the location of the foreign jar package. Please note that if our project is packaged as Project.jar, then as defined above, it should be Project.jar has a related jar package in the same directory (that is, Sqlserver2005.jar, if you have introduced multiple third-party jar packages, it can be separated by a space). Otherwise, the exception in thread "main" Java.lang.NoClassDefFoundError error will appear.

two. Web Service

Build Java version WebService

2.1 What is webservices

It is a universal model of building applications that can be run in any operating system that supports network communication; it is a new branch of Web application that is a self-contained, self-describing, modular application that can be published, positioned, and called through the web. A Web service is an application component that logically provides data and services to other applications. Each application accesses a Web service through a network protocol and some standard data formats (HTTP,XML,SOAP), through the web Service internal execution gets the desired results. WEB Service can perform any function from simple requests to complex business processing. Once deployed, other Web service applications can discover and invoke the services it deploys.

Key technologies and Rules

The following key techniques and rules are used when building and using Web service:

1.XML: Standard method for describing data.

2.SOAP: The protocol that represents the exchange of information.

3.wsdl:web Service Description Language.

4.UDDI: General description, Discovery and integration, which is a platform-independent, XML-based protocol for describing commerce on the Internet.

Xml

Extensible Markup Language (XML) is the basic format for representing data in a Web service platform. In addition to being easy to establish and easy to analyze, the main advantage of XML is that it is platform-independent and vendor-independent. Independence is more important than technical superiority: Software vendors do not choose a technology invented by competitors.

Soap

SOAP is the standard communication protocol for Web service, and soap is simple objectaccess Protocoll's abbreviation, the basic object Access Protocol. It is a standardized XML message format for transmitting messages.

Wsdl

The full name of the WSDL is the Web service Description Language, which is a descriptive language for Web services based on XML format. The main purpose of the Web service provider is to provide all relevant content of their Web services, such as the transmission of the services provided, service method interfaces, interface parameters, service paths, etc., to generate the corresponding full document, published to the user. The user can create the corresponding SOAP request message via HTTP to the WebService provider through this WSDL document, and the Web service passes the SOAP return message back to the requestor after the service request is completed. The service requester then parses the SOAP return message from the WSDL document into what it can understand.

Uddi

To publish a Web service for UDDI registration, UDDI is a specification for creating a registry service so that everyone can register their Web service for publication for the user to find. However, when a service provider wants to publish its Web service to the world, In order to find its services externally, the service provider can register its own web service with the appropriate UDDI business registration site, which currently has 4 UDDI business registration sites worldwide, such as IBM. Because the address URI of the Web service is already given in the WSDL file, the external can make the corresponding Web service call directly from the URI provided by the WSDL. So UDDI is not a required Web service component, and the service party can completely register without UDDI.

2.2 Create and publish your own WebService

1 Installing MyEclipse

2 Configuring Tomcat

Open MyEclipse

Menu bar –> file–>new–> Web Service Project

Here, we use the JAX-ws approach

JAX-ws

JAX-WS is only in Java1.6, the new Web service mode, the annotation-based configuration of Web service, very similar to ASP Web service, the difficulty is more than the Xfire mode of configuration reduced a lot.

REST (JAX-RS)

Less to use

Xfire (OBSOLETE)

More cumbersome configuration

Create a package and class library in service to implement your own business.

We create a user management system that naturally needs to be managed by users.

Publishing a Web Service

Until this WS-Release is complete, the next configuration tomcat

In the pop-up form, expand Myeclipse->servers–>tomcat

Right-click the project to add a library file

Here, all the steps begin to deploy with the configuration complete

Start Tomcat

Locate the deployment icon in the toolbar

Deployment complete, open IE for testing

2.3 Creating a client for testing

At this point, the class library file required by WS will be generated in the project

Create a Call test class

Here, our web service is finished with configuration + testing. In fact, it is not difficult, even if the steps more, more cumbersome, easy to forget, you can be a memo bar, easy to flip!

Reference: http://www.cnblogs.com/lanxuezaipiao/p/3291641.html

http://blog.csdn.net/hehainan_86/article/details/28621989

. NET call to Java implementation method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.