我正在为我的 Web 服务寻找一些用于 SOAP 消息传递的示例代码



我是Web服务的初学者,我想为Web服务使用soap消息传递。我的 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;
    }
}

我想添加肥皂消息。

我试图理解和帮助你。部署 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>

'希望我是对的。

最新更新