我编写了一个调用肥皂服务的客户端,但它发送的请求不是我所期望的。
这是我的代码:
public MessageResponse traGiayToHoSo (MessageRequest request) {
Message message = new Message();
ThongTinXacThuc thongTinXacThuc = new ThongTinXacThuc();
ThongTinHoSo thongTinHoSo = new ThongTinHoSo();
FileDinhKem fileDinhKem = new FileDinhKem();
fileDinhKem.setFileName("FvutqPDmkkC4cWjRsample.docx");
fileDinhKem.setExtension("docx");
fileDinhKem.setByteFile("UEsDBBQABgAIAAAAIQACD0AObDN+AHb0BC9/49I0+Ucq8qbBPyFxyfgjbnRFHdZGrU5P8rUqfPjZtgexsaAAAAAAAAAAAAAzkMAAGN1c3RvbVhtbC9fcmVscy9pdGVtMy54bWwucmVsc1BLBQYAAAAAFgAWALkFAADVRQAAAAA=");
fileDinhKem.setSize("19364");
thongTinXacThuc.setUserName("igate_eoffice");
thongTinXacThuc.setPassWord("igate_eoffice");
thongTinHoSo.setFileDinhKems(new FileDinhKem[]{fileDinhKem});
thongTinHoSo.setMaHoSo("587205");
message.setThongTinHoSo(thongTinHoSo);
message.setThongTinXacThuc(thongTinXacThuc);
request.setMessage(message);
MessageResponse response = (MessageResponse) getWebServiceTemplate().marshalSendAndReceive(request);
System.out.println(response.toString());
return response;
}
使用上述代码,我发送请求如下:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<messageRequest>
<message>
<thongTinHoSo>
<fileDinhKems>
<byteFile>UEsDBBQABgAIAAAAIQACD0AObDN+AHb0BC9/49I0+Ucq8qbBPyFxyfgjbnRFHdZGrU5P8rUqfPjZtgexsaAAAAAAAAAAAAAzkMAAGN1c3RvbVhtbC9fcmVscy9pdGVtMy54bWwucmVsc1BLBQYAAAAAFgAWALkFAADVRQAAAAA=</byteFile>
<extension>docx</extension>
<fileName>FvutqPDmkkC4cWjRsample.docx</fileName>
<size>19364</size>
</fileDinhKems>
<maHoSo>587205</maHoSo>
</thongTinHoSo>
<thongTinXacThuc>
<passWord>igate_eoffice</passWord>
<userName>igate_eoffice</userName>
</thongTinXacThuc>
</message>
</messageRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我想将 xmlns:tns="http://schemas.xmlsoap.org/soap/encoding/" 添加到 SOAP-ENV:Envelope 标记,我该怎么办?
尝试使用以下方式:
import org.springframework.ws.soap.SoapEnvelope;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
public MessageResponse traGiayToHoSo (MessageRequest request) {
// ... Your existing code ...
// Create a SaajSoapMessage
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) getWebServiceTemplate().marshalSendAndReceive(request);
// Get the SoapEnvelope
SoapEnvelope soapEnvelope = saajSoapMessage.getEnvelope();
// Add the xmlns:tns namespace declaration
soapEnvelope.addNamespaceDeclaration("tns", "http://schemas.xmlsoap.org/soap/encoding/");
// Print the modified SOAP request
System.out.println(saajSoapMessage.toString());
// Continue with your logic
MessageResponse response = (MessageResponse) saajSoapMessage.getPayloadSource();
return response;
}
您可以修改代码以添加我发送的 xmlns:tns 命名空间声明。