Send xmlns:xsi and xmlns:xsd namespace in the webservice Soap response

Asked

Viewed 666 times

5

I have a webservice developed in java working perfectly, only that I need to send the namespace xmlns:xsi and xmlns:xsd as shown in the example below:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > </soap:Envelope>'

The answer I am sending is as follows::

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

</soap:Envelope>

If I don’t send the namespace my client gets the answer null.

I’ve tried to Annotation and setting up my jboss and nothing solved. I’m new in Webservice SOAP.


I’m using Jboss Wildfly and Jbossws with CXF.

My interface:

@WebService(targetNamespace = "http://tempuri.org/", name = "NOTFISSoap")
public interface NOTFISSoap {

    @WebMethod(action = "http://tempuri.org/receberNotasFiscais")
    @WebResult(name = "receberNotasFiscaisResult", targetNamespace = "http://tempuri.org/")
    public ReceberNotasFiscaisResult receberNotasFiscais(
            @WebParam(name = "paramNotaFiscal", targetNamespace = "http://tempuri.org/")
            ArrayOfDestinatarioMercadoriaV2 paramNotaFiscal,
            @WebParam(name = "classAuthenticationNotFis_v2", targetNamespace = "http://tempuri.org/", header=true)
            ClassAuthenticationNotFisV2 authentication
    );
}

My implementation:

@WebService(serviceName = "NOTFIS", endpointInterface = "br.com.ws.soap.service.NOTFISSoap", targetNamespace = "http://tempuri.org/")
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class NOTFISSoapImpl implements NOTFISSoap {

    @Override
    public ReceberNotasFiscaisResult receberNotasFiscais(
            ArrayOfDestinatarioMercadoriaV2 paramNotaFiscal, ClassAuthenticationNotFisV2 authentication) {

        // Código
    }
}

Using Soapui, I can consume the service without any problems. Only the client my client can’t get why he waits for these namespaces (xmlns:xsi and xmlns:xsd) in response.

Hugs

  • Can you give more details about the API and the code you are using? After all, there are several technologies that work with XML and SOAP in Java, and each one does it in a different way. This is also important to prevent someone from posting potentially useless answers such as "just replace the string that represents SOAP before sending".

  • I improved the question with more information.

  • That has to do with NF-e?

  • In parts... my client will consume my webservice (that part is ok) by sending some information, I process that information and return a response to it... that part is the problem.

  • The data has to do with NF-e... but only the data... I receive data from recipients and tax notes (his business rule).

1 answer

0

Well, I managed to find a solution to my problem (I don’t know if it would be better to leave).

I downloaded the message at the time of sending through a "message handlers" and added the namespace.

implemented as follows:

Handler-chain.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE xml>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
  <handler-chain>
    <handler>
      <handler-class>br.com.ws.handler.AddNamespaceDeclarationHandler</handler-class>
      </handler>
    <handler>
  </handler-chain>
</handler-chains>

Implementation of the Webservice:

@WebService(serviceName = "NOTFIS", 
            endpointInterface = "br.com.ws.NOTFISSoap",                  
            targetNamespace = "http://tempuri.org/")
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@HandlerChain(file="/handler-chain.xml")
public class NOTFISSoapImpl implements NOTFISSoap {
    // Código...
}

My "message handlers"

public class AddNamespaceDeclarationHandler implements SOAPHandler<SOAPMessageContext> {


    private void addNamespaceDeclaration(SOAPMessageContext smc) {

        try {

            if((boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {

                SOAPMessage message = smc.getMessage();

                SOAPPart part         = message.getSOAPPart();
                SOAPHeader header     = message.getSOAPHeader();
                SOAPEnvelope envelope = part.getEnvelope();

                header.detachNode();

                envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");   
            }
        }
        catch (Exception e) {
            System.out.printf("Exception in handler: %s%n", e);
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.