我正在用apache-cxf编写一个soap web服务。我遵循代码第一种方法。问题是,我没有在响应中获得“soap:header”标签。我已经通过其他wsdl和java实现类,并且无法找到需要在wsdl或SEI中添加的内容以获取soap:header块作为响应如果有人可以帮助我,请告诉我。如果需要,我会分享更多细节。
我的webservice类看起来像 -
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by Apache CXF 3.1.11
* 2017-05-01T12:11:39.200+05:30
* Generated source version: 3.1.11
*
*/
@WebService(targetNamespace = "http://webservice.sample.com", name = "SampleWebService")
@XmlSeeAlso({ObjectFactory.class})
public interface SampleWebService {
@WebResult(name = "Response", targetNamespace = "" )
@RequestWrapper(localName = "requestWrapper", targetNamespace = "http://webservice.sample.com", className = "com.sample")
@WebMethod
@ResponseWrapper(localName = "responseWrapper", targetNamespace = "http://webservice.sample.com", className = "com.sample" )
public com.sample.Response requestWrapper(
@WebParam(name = "request", targetNamespace = "http://requests.webservice.sample.com")
com.sample.Request request
);
}
和wsdl -
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://webservice.sample.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="SampleWebServiceService" targetNamespace="http://webservice.sample.com">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://response.webservice.sample.com" xmlns:ns1="http://requests.webservice.sample.com" targetNamespace="http://webservice.sample.com" version="1.0">
<xs:import namespace="http://requests.webservice.sample.com"/>
<xs:import namespace="http://response.webservice.sample.com"/>
<xs:element name="requestWrapper" type="ns1:Create"/>
<xs:element name="responseWrapper" type="ns2:CreateConfirmation"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://common.sample.com" targetNamespace="http://response.webservice.sample.com" version="1.0">
<xs:import namespace="http://common.sample.com"/>
<xs:complexType name="CreateConfirmation">
<xs:sequence>
<xs:element form="qualified" name="Response">
<xs:complexType>
<xs:sequence>
<xs:element form="qualified" name="ID" type="xs:string"/>
<xs:element form="qualified" maxOccurs="unbounded" minOccurs="0" name="Error" type="ns1:Error"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://requests.webservice.sample.com" version="1.0">
<xs:complexType name="Create">
<xs:sequence>
<xs:element form="qualified" name="Request">
<xs:complexType>
<xs:sequence>
<xs:element form="qualified" name="Name" type="xs:string"/>
<xs:element form="qualified" name="CreationDate" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://common.sample.com" version="1.0">
<xs:complexType name="Error">
<xs:sequence>
<xs:element name="ErrorCode" type="xs:string"/>
<xs:element name="ErrorMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="requestWrapper">
<wsdl:part element="tns:requestWrapper" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="responseWrapper">
<wsdl:part element="tns:responseWrapper" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="SampleWebService">
<wsdl:operation name="requestWrapper">
<wsdl:input message="tns:requestWrapper" name="requestWrapper"></wsdl:input>
<wsdl:output message="tns:responseWrapper" name="responseWrapper"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SampleWebServiceServiceSoapBinding" type="tns:SampleWebService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="requestWrapper">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="requestWrapper">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="responseWrapper">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SampleWebServiceService">
<wsdl:port binding="tns:SampleWebServiceServiceSoapBinding" name="SampleWebService">
<wsdlsoap:address location="http://localhost:8181/cxf/SampleWebService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
肥皂要求 -
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.sample.com" xmlns:ord="http://requests.webservice.sample.com">
<soapenv:Header/>
<soapenv:Body>
<web:requestWrapper>
<ord:Request>
<ord:Name>Harry</ord:Name>
<ord:CreationDate>2015-09-09T12:45:00</ord:CreationDate>
</ord:Request>
</web:requestWrapper>
</soapenv:Body>
</soapenv:Envelope>
预期回应 -
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<ns2:responseWrapper xmlns:ns2="http://common.sample.com" xmlns="http://response.sample.com">
<ID>12345678910</ID>
</ns2:responseWrapper>
</soap:Body>
</soap:Envelope>
实际回应 -
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:responseWrapper xmlns:ns2="http://common.sample.com" xmlns="http://response.sample.com">
<ID>12345678910</ID>
</ns2:responseWrapper>
</soap:Body>
</soap:Envelope>
答案 0 :(得分:0)
不需要空标题元素。如果要添加标题,请添加例如方法参数
@WebParam(partName = "bankHeader", mode = WebParam.Mode.OUT, name = "bankRequestHeader", targetNamespace = "http://example.bank.skjolber.github.com/v1", header = true)
javax.xml.ws.Holder<BankRequestHeader> bankHeader
(样本是通过移动并输入this sample中的输出标题生成的。)