import
java.io.IOException;
import
java.net.InetSocketAddress;
import
java.util.concurrent.ExecutorService;
import
java.util.concurrent.Executors;
import
javax.xml.ws.Endpoint;
import
com.sun.net.httpserver.HttpContext;
import
com.sun.net.httpserver.HttpServer;
public
class
HttpServerTestService {
public
static
void
main(String[] args) {
try
{
HttpServer server
=
HttpServer.create(
new
InetSocketAddress(
8888
),
0
);
ExecutorService threads
=
Executors.newFixedThreadPool(
10
);
server.setExecutor(threads);
server.start();
Endpoint endpoint
=
Endpoint.create(
new
Hello());//响应类
HttpContext context
=
server.createContext(
"
/hello
"
);//发布URL
endpoint.publish(context);
}
catch
(IOException ioe) {
ioe.printStackTrace();
}
}
}
import
javax.jws.WebMethod;
import
javax.jws.WebService;
import
javax.jws.soap.SOAPBinding;
@WebService(targetNamespace
=
"
http://jdk.study.hermit.org/client
"
)
@SOAPBinding(style
=
SOAPBinding.Style.RPC)
public
class
Hello {
@WebMethod
public
String sayHello(String name) {
return
"
hello:
"
+
name;
}
}
访问:
http://127.0.0.1:8888/hello?wsdl <?xml version="1.0" encoding="UTF-8" ?>
- <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://jdk.study.hermit.org/client" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://jdk.study.hermit.org/client" name="HelloService">
<types />
- <message name="sayHello">
<part name="arg0" type="xsd:string" />
</message>
- <message name="sayHelloResponse">
<part name="return" type="xsd:string" />
</message>
- <portType name="Hello">
- <operation name="sayHello" parameterOrder="arg0">
<input message="tns:sayHello" />
<output message="tns:sayHelloResponse" />
</operation>
</portType>
- <binding name="HelloPortBinding" type="tns:Hello">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <operation name="sayHello">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" namespace="http://jdk.study.hermit.org/client" />
</input>
- <output>
<soap:body use="literal" namespace="http://jdk.study.hermit.org/client" />
</output>
</operation>
</binding>
- <service name="HelloService">
- <port name="HelloPort" binding="tns:HelloPortBinding">
<soap:address location="http://127.0.0.1:8888/hello" />
</port>
</service>
</definitions>
posted on 2007-06-22 14:21
交口称赞 阅读(1673)
评论(1) 编辑 收藏 所属分类:
Java6