How do I add a namespace reference to a SOAP response with Apache Axis2 and WSDL2Java

前端 未结 2 1886
醉酒成梦
醉酒成梦 2020-12-19 05:17

I\'m looking at the SOAP output from a web service I\'m developing, and I noticed something curious:



        
相关标签:
2条回答
  • 2020-12-19 05:35

    Other option is that the variable MY_QNAME has the prefix empty.

    public static final QName MY_QNAME = new QName("http://www.hello.com/Service/",
                "tagname",
                "prefix");
    

    So, if you fill it, then it works.

    0 讨论(0)
  • 2020-12-19 05:48

    Using WSDL2Java

    If you have used the Axis2 WSDL2Java tool you're kind of stuck with what it generates for you. However you can try to change the skeleton in this section:

       // create SOAP envelope with that payload
       org.apache.axiom.soap.SOAPEnvelope env = null;
       env = toEnvelope(
           getFactory(_operationClient.getOptions().getSoapVersionURI()),
           methodName,
           optimizeContent(new javax.xml.namespace.QName
           ("http://tempuri.org/","methodName")));
    
    //adding SOAP soap_headers
    _serviceClient.addHeadersToEnvelope(env);
    

    To add the namespace to the envelope add these lines somewhere in there:

    OMNamespace xsi = getFactory(_operationClient.getOptions().getSoapVersionURI()).
        createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
    
    env.declareNamespace(xsi);
    

    Hand-coded

    If you are "hand-coding" the service you might do something like this:

    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();   
    SOAPEnvelope envelope = fac.getDefaultEnvelope();
    OMNamespace xsi = fac.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
    
    envelope.declareNamespace(xsi);
    OMNamespace methodNs = fac.createOMNamespace("http://somedomain.com/wsinterface", "ns1");
    
    OMElement method = fac.createOMElement("CreateEntityTypesResponse", methodNs);
    
    //add the newkeys and errors as OMElements here...
    

    Exposing service in aar

    If you are creating a service inside an aar you may be able to influence the SOAP message produced by using the target namespace or schema namespace properties (see this article).

    Hope that helps.

    0 讨论(0)
提交回复
热议问题