0

我想知道是否有人可以帮助我处理 ksoap2 标头。这是我的soapUI 请求,我需要将其转换为使用带有ksoap2 的服务。

<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();
        }

    }

我的错误在哪里?

4

1 回答 1

0

您需要将此添加到 android 清单文件中。

<uses-permission android:name="android.permission.INTERNET" />
于 2013-02-19T11:26:01.747 回答