Consumir webservice SAP utilizando KSOAP2

0 respostas
L

Pessoal,

estou desenvolvendo uma aplicação básica que faz a chamada de um webservice publicado via SAP PI. O formato esperado pelo webservice é um arquivo XML, porém a request chega ao webservice em formato texto.

Segue abaixo o arquivo WSDL do webservice:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:p1="http://CSMobile.autenticaApp.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="MI_SyncOutAutenticaMobile" targetNamespace="http://CSMobile.autenticaApp.com">
    <wsdl:types>
        <xsd:schema targetNamespace="http://CSMobile.autenticaApp.com" xmlns="http://CSMobile.autenticaApp.com" xmlns:p1="http://CSMobile.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:import namespace="http://CSMobile.com"/>
            <xsd:element name="MT_MobileRetornoAutentica" type="DT_MobileRetornoAutentica"/>
            <xsd:element name="MT_MobileEnvioAutentica" type="p1:DT_EstruturaUser"/>
            <xsd:complexType name="DT_MobileRetornoAutentica">
                <xsd:sequence>
                    <xsd:element name="MobileRetornoMenu" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">589a1ce0086c11e0ab0ffd6c0a0d01ac</xsd:appinfo>
                        </xsd:annotation>
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="Menu" type="p1:DT_EstruturaMenu" minOccurs="0" maxOccurs="unbounded" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                                    <xsd:annotation>
                                        <xsd:appinfo source="http://sap.com/xi/TextID">589a1ce1086c11e0bd7afd6c0a0d01ac</xsd:appinfo>
                                    </xsd:annotation>
                                </xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="MobileRetornoMsg" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">5cfcb1e008a711e0a0c1f3f6c0a80065</xsd:appinfo>
                        </xsd:annotation>
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="Msg" type="p1:DT_EstruturaMsg" minOccurs="0" maxOccurs="unbounded" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                                    <xsd:annotation>
                                        <xsd:appinfo source="http://sap.com/xi/TextID">94c94d900f9111e0becac8a8c0a80066</xsd:appinfo>
                                    </xsd:annotation>
                                </xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
        <xsd:schema targetNamespace="http://CSMobile.com" xmlns="http://CSMobile.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:complexType name="DT_EstruturaMenu">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">50ccf9ca0f9111e0b59b0024e87e9879</xsd:appinfo>
                </xsd:annotation>
                <xsd:sequence>
                    <xsd:element name="APROID" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">cd187aa0077011e0c92be7040a0d01ac</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="LOGONE" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">ff081f900f8e11e0a368c8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMID1" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283d5bc006d711e0b88200ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMIV1" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80006d711e099d200ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMID2" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80106d711e08ee900ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMIV2" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80206d711e0c9a100ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMID3" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80306d711e0a7b700ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMIV3" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80406d711e085c900ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMID4" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80506d711e0c7b900ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMIV4" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80606d711e0b57200ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMID5" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283df80706d711e0aa7000ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMIV5" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283e1f1006d711e0801500ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMID6" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283e1f1106d711e085e200ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="CAMIV6" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">283e1f1206d711e09be000ffafd1c406</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="DT_EstruturaUser">
                <xsd:sequence>
                    <xsd:element name="USERID" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">c95cbc000f9011e0c14dc8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="USERPW" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">c95cbc010f9011e09595c8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="APROID" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">c95cbc020f9011e0cda8c8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="USEREX" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">c95cbc030f9011e09f0ec8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="USEPEX" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">c95cbc040f9011e0c650c8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="DT_EstruturaMsg">
                <xsd:sequence>
                    <xsd:element name="TIPMSG" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">5eeff9000f8f11e08324c8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="TXTMSG" type="xsd:string" minOccurs="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">5eeff9010f8f11e0b886c8a8c0a80066</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="MT_MobileEnvioAutentica">
        <wsdl:part name="MT_MobileEnvioAutentica" element="p1:MT_MobileEnvioAutentica" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
    </wsdl:message>
    <wsdl:message name="MT_MobileRetornoAutentica">
        <wsdl:part name="MT_MobileRetornoAutentica" element="p1:MT_MobileRetornoAutentica" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
    </wsdl:message>
    <wsdl:portType name="MI_SyncOutAutenticaMobile">
        <wsdl:operation name="MI_SyncOutAutenticaMobile">
            <wsdl:input message="p1:MT_MobileEnvioAutentica"/>
            <wsdl:output message="p1:MT_MobileRetornoAutentica"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="MI_SyncOutAutenticaMobileBinding" type="p1:MI_SyncOutAutenticaMobile" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
        <wsdl:operation name="MI_SyncOutAutenticaMobile">
            <soap:operation soapAction="http://sap.com/xi/WebService/soap1.1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            <wsdl:input>
                <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="MI_SyncOutAutenticaMobileService">
        <wsdl:port name="MI_SyncOutAutenticaMobilePort" binding="p1:MI_SyncOutAutenticaMobileBinding" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
            <soap:address location="http://SRV-A17:8000/sap/xi/engine?type=entry&amp;version=3.0&amp;Sender.Party=http%3A%2F%2Fsap.com%2Fxi%2FXI%3AXIParty%3AMobileCS&amp;Sender.Service=BE_MobileCS&amp;Interface=http%3A%2F%2FCSMobile.autenticaApp.com%5EMI_SyncOutAutenticaMobile" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

E aqui está meu código Java que monta a request e envia pelo SOAP Envelope:

public Button.OnClickListener btTestListener = new Button.OnClickListener() {
        public void onClick(View v) {
            try {
                // Create SOAP request
                SoapObject request = new SoapObject(NAMESPACE, OPERATION);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                
                request.addProperty("USERID", "ABAP02");
                request.addProperty("USERPW", "cs2010");
                request.addProperty("APROID", " ");
                request.addProperty("USEREX", " ");
                request.addProperty("USEPEX", " ");
                
                envelope.setOutputSoapObject(request);
                envelope.setAddAdornments(false);
                envelope.implicitTypes = true;
                
                HttpTransportSE httpTransport = new HttpTransportSE(URL);
                httpTransport.debug = true;
    
                try{
                    httpTransport.call(SOAP_ACTION, envelope);
                
                    // Get response from envelope
                    Object result = envelope.getResponse();
                                    
                    // Display result
                    Toast.makeText(AppSoap.this, result.toString(),
                        50000).show();

                } catch (Exception e) {
                e.printStackTrace();
                }
            
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    };

Alguém poderia me dar uma ajuda? Já tentei diversos métodos e nada!

Obrigado.

Criado 19 de janeiro de 2011
Respostas 0
Participantes 1