Interoperability between C # and Java using web services without Java EE application server?

I am in a difficult position: We have a third-party enterprise system that provides a Java interface. However, we are a 100% .Net-oriented development team. Essentially, I need to wrap the Java API with something that can call C # code.

Web services will be great, but the only Java application server supported in our infrastructure is WebSphere 6.1. This means that the ancient (and obsolete) JAX-RPC web services structure is the only way for us to open web services. Just getting a simple evidential concept working here was a nightmare (due to Java inexperience, WebSphere is awful, JAX-RPC is awkward and a lot of JAR hell).

The new JAX-WS 2.0 web services framework in JAVA EE 5 looks great - is there a way to run it without using the entire Java application server? For example, in .Net WCF (Windows Communication Framework), you can host services almost anywhere (in a process, Windows service, IIS 6/7, etc.).

What is the easiest way to wrap this library with some web services?

+2
source share
4 answers

In the end, I found a solution that was much simpler than any of the above. We created some simple classes (for example, the doPing () method in @ Thorbjørn Ravn Andersen's answer) with annotations @javax.jws.WebServiceand @javax.jws.WebMethodthen deployed them using:

string url = "http://localhost:8282/MyService"
MyService serviceInstance = new MyService();
Endpoint svc = Endpoint.publish(url, serviceInstance);

Visual Studio http://localhost:8282/MyService?wsdl . , .

. Java Service Wrapper, / JVM .. .

, .NET, Java , .

0

.

Java-, 1) @WebMetod 2) 3- -, Metro- - https://metro.dev.java.net/ - - Servlet 2.5 ( -), -, Jetty, , Tomcat.

http://archive.midrange.com/java400-l/200904/msg00071.html


Metro 1.4 https://metro.dev.java.net/1.4/ ( 1.5 , ), jar.

webservices-api.jar, webservices-rt.jar, webservices-extra-api.jar webservices-extra.jar( ) , "" jarfiles, tomcat - , ${TOMCAT}/lib Tomcat 6. [1]

Eclipse, , WAR:

  • JRE - Java 5, webservices-api.jar ( ). Java 6, .

  • foo.Ping, :


package foo;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 Ping is a simple web service class providing a "yes, we have contact" class.
 Currently the doPing() method provides a response with the host name and
 address (if available) and the current server time.

*/
@javax.jws.WebService
public class Ping {

@javax.jws.WebMethod(action = "doPing")
public String doPing() {
System.out.println("Ping.doPing() called.");

String hostName;
try {
  hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
  hostName = "unknown (" + e.getMessage() + ")";
}

String hostAddress;
try {
  hostAddress = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
  hostAddress = "unknown (" + e.getMessage() + ")";
}

return "Reached '" + hostName + "' (" + hostAddress + ") at "
    + new java.util.Date() + " java.version="
    + System.getProperty("java.version", "(not set)");
  }
}

  • WEB-INF/web.xml :
    <listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    <servlet>
    <description>JAX-WS endpoint - this servlet must handle all endpoints</description>
    <display-name>webservice</display-name>
    <servlet-name>webservice</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- each endpoint must have a mapping to the JAX-WS endpoint servlet -->

    <servlet-mapping>
    <servlet-name>webservice</servlet-name>
    <url-pattern>/ws</url-pattern>
    </servlet-mapping>
  • WEB-INF/sun-jaxws.xml:
    <endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
        <endpoint name='ping' implementation='foo.Ping'url-pattern='/ws'>
        </endpoint
    </endpoints>
  • , web.xml, sun-jaxws.xml!

  • !

Tomcat, , "/ws" -. http://localhost:8080/foo/ws;. , WSDL -, Ping. WSDL, - Eclipse IDE Java EE WSDCi.

, :)

[1] , .

+2

" Java, , - WebSphere 6.1" , . , , -.

, : http://docs.codehaus.org/display/JETTY/J2se6HttpServerSPI

+1

JDK, , , WebSphere, apache.

-, Java-, , java.

, Jax-WS , , , - JDK5, JAX-WS , webservice .NET 2.0.

0

Source: https://habr.com/ru/post/1722499/


All Articles