用于 Java 的进程内 SOAP 服务服务器 [英] In-process SOAP service server for Java
问题描述
好的,我正在开发一个将部署到许多机器(Windows、Linux、AIX、z/Linux、openVMS 等)的程序.我希望该应用程序包含 SOAP Web 服务,但我不想捆绑 tomcat 或为这些服务运行单独的服务(我希望它们与应用程序的其余部分在同一进程中).
基本上我正在寻找的是我可以定义一个类的东西(比如WebServices
).我也可以编写 WSDL 或任何其他类型的服务描述.我想要这样的东西:
SOAPServer 服务器 = makeMeASoapServer();//在服务器上做配置server.add(new WebService(...));server.listen(端口);
显然名称和参数会有所不同.
我一直在看Axis,好像它提供了这个,但我不知道我需要使用哪些类.我想要这种行为是疯了吗?我不敢相信更多的人没有在寻找这个,我一直在使用 .NET 客户端中的嵌入式 Web 服务这样做.
似乎 jdk 6.0 已经附带了一个 jax-ws 实现,以及一个可以嵌入的小服务器.我还没有弄清楚所有的部分,但这是一个开始:
mkdir -p helloservice/endpoint/
helloservice/endpoint/Hello.java :
package helloservice.endpoint;导入 javax.jws.WebService;@网络服务()公共课你好{private String message = new String("你好,");public void Hello() {}公共字符串sayHello(字符串名称){返回消息 + 姓名 + ".";}}
helloservice/endpoint/Server.java:
package helloservice.endpoint;导入 javax.xml.ws.Endpoint;公共类服务器{受保护的服务器()抛出异常{System.out.println("启动服务器");对象实现者 = new Hello();字符串地址 = "http://localhost:9000/SoapContext/SoapPort";Endpoint.publish(地址,实现者);}public static void main(String args[]) 抛出异常 {新服务器();System.out.println("服务器准备好...");Thread.sleep(5 * 60 * 1000);System.out.println("服务器退出");System.exit(0);}}
构建事物:
mkdir 构建javac -d build helloservice/endpoint/*java$JAVA_HOME/wsgen -d build -s build -classpath .helloservice.endpoint.Hello
运行事物:
java -cp build helloservice.endpoint.Server
现在在 http://localhost:9000/SoapContext/SoapPort 上运行的东西.您可以在 http://localhost:9000/SoapContext/SoapPort?WSDL 上获取 wsdl>
还没有开始制作客户..
OK, I am developing a program which will be deployed to lots of machines (Windows, Linux, AIX, z/Linux, openVMS, etc.). I want that application to contain a SOAP web service, but I don't want to bundle tomcat or run a separate service for the services (I want them in the same process as the rest of the application).
Basically what I'm looking for is something where I can define a class (say WebServices
). I'm OK with writing WSDL or any other kind of service description as well. The I want something like this:
SOAPServer server = makeMeASoapServer();
//do config on the server
server.add(new WebService(...));
server.listen(port);
Obviously the names and parameters will be different.
I've been looking at Axis, and it seems like it provides this, but I don't know what classes I need to use. Am I crazy in wanting this kind of behavior? I can't believe more people aren't looking for this, I do this all the time with embedded web services within .NET clients.
Seems jdk 6.0 already comes with a jax-ws implementation, and a little server you can embed. I havn't figured out all the pieces but here's a start:
mkdir -p helloservice/endpoint/
helloservice/endpoint/Hello.java :
package helloservice.endpoint;
import javax.jws.WebService;
@WebService()
public class Hello {
private String message = new String("Hello, ");
public void Hello() {}
public String sayHello(String name) {
return message + name + ".";
}
}
helloservice/endpoint/Server.java:
package helloservice.endpoint;
import javax.xml.ws.Endpoint;
public class Server {
protected Server() throws Exception {
System.out.println("Starting Server");
Object implementor = new Hello();
String address = "http://localhost:9000/SoapContext/SoapPort";
Endpoint.publish(address, implementor);
}
public static void main(String args[]) throws Exception {
new Server();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
}
Build the thing:
mkdir build
javac -d build helloservice/endpoint/*java
$JAVA_HOME/wsgen -d build -s build -classpath . helloservice.endpoint.Hello
Run the thing:
java -cp build helloservice.endpoint.Server
Somethings running on http://localhost:9000/SoapContext/SoapPort now. You can get the wsdl on http://localhost:9000/SoapContext/SoapPort?WSDL
Havn't gotten around to making a client yet..
这篇关于用于 Java 的进程内 SOAP 服务服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!