使用HEADER消费WSDL ksoap

时间:2018-07-11 10:34:50

标签: java android soap wsdl

从android studio quiro使用WSDL,其中包含用于身份验证的标头。 我传递了xml文件和我的代码,以防您可以告诉我错误在哪里。

问题是它引发了我异常

我认为问题在于传递标题。头如何通过ksoap2传递?

这是我要使用的WSDL,下面放了android studio的代码

XML

<wsdl:definitions targetNamespace="urn:HPD_IncidentInterface_WS">
−
<wsdl:types>
−
<xsd:schema elementFormDefault="qualified" targetNamespace="urn:HPD_IncidentInterface_WS">
<xsd:import namespace="http://tempuri.org"/>
<xsd:element name="HelpDesk_Query_Service" type="s0:GetInputMap"/>
−
<xsd:complexType name="GetInputMap">
−
<xsd:sequence>
<xsd:element name="Incident_Number" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="HelpDesk_Query_ServiceResponse" type="s0:GetOutputMap"/>
−
<xsd:complexType name="GetOutputMap">
−

AQUI EL CODIGO

public class WebService {

    protected String doInBackground(Void... params) {

//WebService - Opciones


        final String NAMESPACE = "urn:HPD_IncidentInterface_WS";
        //final String URL = "http://10.240.240.80:8080/arsys/services/ARService?server=desitsm01&webService=HPD_IncidentInterface_WS";
        final String URL = "http://10.240.240.80:8080/arsys/WSDL/public/desitsm01/HPD_IncidentInterface_WS";
        final String METHOD_NAME = "HelpDesk_Query_Service";
        final String SOAP_ACTION = "urn:HPD_IncidentInterface_WS/HelpDesk_Query_Service";
        //final String SOAP_ACTION = "Helpdesk_Query_Service";


        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
       // HeaderProperty hp = new HeaderProperty();

        //preparamos el cuerpo para la consulta
        //request.addProperty("userName", "csu_cau2");
        //request.addProperty("password", "csu_cau2");
        request.addProperty("Incident_Number", "INC000000068829");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        //creamos la cabecera
        Element[] header = new Element[1];
        header [0] = new Element().createElement(NAMESPACE, "AuthenticationInfo");
        //header[0].setAttribute(null, "mustUnderstand","1");

        Element username = new Element().createElement(NAMESPACE, "userName");
        username.addChild(Node.TEXT, "csu_cau2");
        header[0].addChild(Node.ELEMENT,username);

        Element pass = new Element().createElement(NAMESPACE,"password");
        //pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
        pass.addChild(Node.TEXT, "csu_cau2");

        header[0].addChild(Node.ELEMENT, pass);

        // add header to envelope
        envelope.headerOut = header;
        Log.i("header", "" + envelope.headerOut.toString());

        envelope.dotNet = true;

        envelope.bodyOut=request;

        HttpTransportSE androidHttpTransport =  new HttpTransportSE(URL);
        String res="";

        try{
            androidHttpTransport.call(SOAP_ACTION, envelope);
            //SoapObject response = (SoapObject)envelope.bodyIn;
            res=envelope.getResponse().toString();

        }catch(Exception e){Log.d("Prova",e.toString());     res="error"; return res;}
        res="error";
        Log.d("Prova", res);
        return res;
    }  

0 个答案:

没有答案