简体   繁体   中英

<soap:header/> block in not coming in soap response

I am writing a soap web service with apache-cxf. I am following code first approach. The issue is , i am not getting "soap:header" tag under in response.I have gone through other wsdl and java implementation classes and not able to find what needs to be added in wsdl or SEI to get soap:header block in response.Please let me know if any one can help me in this.I would share more details if required.

My webservice class looks like -

    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
    );
}

and 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>

Soap Request -

<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>

Expected Response -

<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>

Actual Response -

<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>

An empty header element is not required. If you want to add a header, add for example the method parameter

@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

(The sample was generated by moving and input to output header in this sample .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM