我是网络服务的初学者,我想将肥皂消息用于网络服务。我的Web服务工作正常,我希望与客户端的所有通信都使用SOAP消息。在谷歌搜索,我无法找到我想要的一些好的示例代码。服务和客户端都是Java。我有一些网络方法如下。
public SomethingDTO getSomethingById(Long id) {
try {
InitialContext ctx2 = new InitialContext();
UserTransaction utx = (UserTransaction) ctx2.lookup("java:module/UserTransaction");
utx.begin();
SomethingDTO something = null;
if (id != null) {
SomethingDAO somethingDAO = new SomethingDAO();
something = somethingDAO.findById(id, false);
if (something == null) {
System.out.println("No data found");
}
}
utx.commit();
return something;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
我想添加肥皂信息。
答案 0 :(得分:1)
我试图理解并帮助你。 部署Web服务时,SOAP消息将如下所示。
`
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.intech.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.intech.com/" name="HelloWorldImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.intech.com/" schemaLocation="http://localhost:9999/ws/hello?xsd=1"/>
</xsd:schema>
</types>
<message name="getSomethingById">
<part name="arg0" type="xsd:long"/>
</message>
<message name="getSomethingByIdResponse">
<part name="return" type="tns:somethingDTO"/>
</message>
<portType name="HelloWorld">
<operation name="getSomethingById">
<input message="tns:getSomethingById"/>
<output message="tns:getSomethingByIdResponse"/>
</operation>
</portType>
<binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="getSomethingById">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://ws.intech.com/"/>
</input>
<output>
<soap:body use="literal" namespace="http://ws.intech.com/"/>
</output>
</operation>
</binding>
<service name="HelloWorldImplService">
<port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
<soap:address location="http://localhost:9999/ws/hello"/>
</port>
</service>
</definitions>
` 希望我是对的。