Ksoap2标头输入/输出

时间:2013-02-19 10:30:19

标签: android wcf ksoap2

我想知道是否有人可以帮助我使用kso​​ap2标头。 这是我的soapUI请求,我需要转换为使用kso​​ap2的服务。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tim="http://www.xxx.co.uk/schemas/111.Security">
   <soapenv:Header>
      <ip>127.0.0.1</ip>
   </soapenv:Header>
   <soapenv:Body>
      <tim:Login>
         <tim:userName>username</tim:userName>
         <tim:password>pass</tim:password>
      </tim:Login>
   </soapenv:Body>
</soapenv:Envelope>

这是我的班级日食:

private static final String SOAP_ACTION="http://www.xxx.co.uk/schemas/111.Security/ISecurity/Login" ;
    private static final String METHOD_NAME="Login";
    private static final String NAMESPACE="http://www.xxx.co.uk/schemas/111.Security";
    private static final String URL="http://192.168.5.68:55969/Timesheet/yyy.111.Services/Security.svc";

和buttonclicklistener是我的行动:

@Override
    public void onClick(View v) 
    {

        try 
        {            
            SoapObject soap = new SoapObject(NAMESPACE, METHOD_NAME);
            soap.addProperty("userName" ,txtUserName.getText().toString()); 
            soap.addProperty("password",txtPassword.getText().toString());

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;

            Element[] headers = new Element[1];             
            Element element = new Element();
            element.setName("ip");
            element.setNamespace(NAMESPACE);        
            element.addChild(Element.TEXT, "127.0.0.1");        

            headers[0] = element;                         
            envelope.setOutputSoapObject(soap);
            envelope.headerOut = headers;
            envelope.bodyOut = soap;


            HttpTransportSE transport = new HttpTransportSE(URL);
            transport.call(SOAP_ACTION, envelope);

            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            String resultValue = response.toString();

            lblStatus.setText(resultValue);
        } 
        catch (Exception e) 
        {                   
            new AlertDialog.Builder(this).setTitle("Error").setMessage("Error").show();
        }

    }

我的错误在哪里?

1 个答案:

答案 0 :(得分:0)

您需要将其添加到Android清单文件中。

<uses-permission android:name="android.permission.INTERNET" />