2013-02-19 68 views
0

我想知道是否有人可以用ksoap2标题帮我。 这是我的soapUI请求,我需要转换为使用kso​​ap2服务。Ksoap2 header in/out

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

    } 

哪里是我的错?

+0

你得到的错误是什么? – Sajeetharan 2013-02-19 10:45:51

+0

非法论证异常 – user2086174 2013-02-19 11:22:06

+0

使用该库的Propertyinfo并通过论证。 – Sajeetharan 2013-02-19 11:26:43

回答

0

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

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

添加,仍然没有变化.. – user2086174 2013-02-19 11:29:04

+0

检查我上面的评论 – Sajeetharan 2013-02-19 11:31:08