2014-03-25 89 views
2

我试图通过SOAP发送xml以获取特定响应。我试图用我的默认引脚登录。正确的响应将包括一个用户标识,但会变为零。通过SOAP发送XML数据时无法获得响应

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() 
      .permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 

    // Create the soap request object 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    // Set the property info for the to currency 
    PropertyInfo value = new PropertyInfo(); 
    value.setName("xml"); 
    value.setValue(xml); 
    value.setType(String.class); 
    request.addProperty(value); 


    // Create the envelop.Envelop will be used to send the request 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
      SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request);   
    envelope.dotNet = true;  

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

    try { 
     androidHttpTransport.call(SOAP_ACTION, envelope);    
     SoapObject response = (SoapObject)envelope.bodyIn; 

     result = response.getProperty(0).toString();   

     Log.i("RES", result); 


    } catch (Exception e) { 

     result = "EXCEP " + e.toString(); 
    } 

我的XML是

 <?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
<pinLogin xmlns="http://tempuri.org/"> 
    <pin1>string</pin1> 
    <pin2>string</pin2> 
    <pin3>string</pin3> 
    <pin4>string</pin4> 
</pinLogin> 

我应该得到这样

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
<pinLoginResponse xmlns="http://tempuri.org/"> 
    <pinLoginResult> 
    <username>string</username> 
    <userID>guid</userID> 
    <isBusinessUser>boolean</isBusinessUser> 
    <functionOk>boolean</functionOk> 
    <checkAmount>boolean</checkAmount> 
    <refundRequested>boolean</refundRequested> 
    <isPaid>boolean</isPaid> 
    <duplicateUser>boolean</duplicateUser> 
    <isvalid>boolean</isvalid> 
    <funsdok>boolean</funsdok> 
    <emailok>boolean</emailok> 
    <recorddbadded>boolean</recorddbadded> 
    <transisvalid>boolean</transisvalid> 
    <user2isvalid>boolean</user2isvalid> 
    </pinLoginResult> 
</pinLoginResponse> 
</soap:Body> 
</soap:Envelope> 

的回应,但我得到这样的事情

anyType{userID=00000000-0000-0000-0000-000000000000;isBusinessUser=false; functionOk=false; checkAmount=false;refundRequested=false; ispaid=false; duplicateUser=false; 
isValid=false; funsdok=false;emailok=false;recorddbadded=false; 
transisvalid=false;user2isvalid=false;} 

有没有人有任何想法有什么问题...

+0

你是否在浏览器中测试你的服务?用一些样本值进行测试。 – Sree

+0

是的,我确实测试过。它确实返回特定引脚的有效用户ID – suja

+0

result = response.getProperty(0).toString();给出了上述结果 – Sree

回答

2

终于设法破解它。

对我来说,最初我给一个完整字符串的数据,并从edittext中添加了一些数据,现在我将pin号码分配给字符串,并通过PropertyIndo将这些字符串添加到Soap请求中,并添加了xmlversiontag。我已添加工作代码。

private final String NAMESPACE = ""; 
private final String URL = ""; 
private final String SOAP_ACTION = ""; 
private final String METHOD_NAME = ""; 
String _TAG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";   
String pin1 = "a"; 
String pin2 = "b"; 
String pin3 = "8"; 
String pin4 = "d"; 

在我的SOAPCall方法

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
StrictMode.setThreadPolicy(policy); 

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

PropertyInfo _pin1 = new PropertyInfo(); 
_pin1.setName("pin1"); 
_pin1.setValue(pin1); 
_pin1.setType(String.class); 

PropertyInfo _pin2 = new PropertyInfo(); 
_pin2.setName("pin2"); 
_pin2.setValue(pin2); 
_pin2.setType(String.class); 

PropertyInfo _pin3 = new PropertyInfo(); 
_pin3.setName("pin3"); 
_pin3.setValue(pin3); 
_pin3.setType(String.class); 

PropertyInfo _pin4 = new PropertyInfo(); 
_pin4.setName("pin4"); 
_pin4.setValue(pin4); 
_pin4.setType(String.class); 


request.addProperty(_pin1); 
request.addProperty(_pin2); 
request.addProperty(_pin3); 
request.addProperty(_pin4); 

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

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

try { 
     androidHttpTransport.setXmlVersionTag(_TAG); 
     androidHttpTransport.call(SOAP_ACTION, envelope); 
     SoapObject response = (SoapObject)envelope.bodyIn; 
     result = response.getProperty(0).toString(); 
     Log.i("RES", result); 
    } 
catch(Exception e){ 
     Log.i("ERR" , e.toString()); 
} 

还做您的清单文件中添加权限互联网。我希望这可能对某人有用。