2012-09-10 40 views
0

如何通過SOAP方法傳遞兩個參數以從android中使用Web服務。 我試過了,但我無法從android使用該Web服務。傳遞兩個參數以從android中使用Web服務

對此提出建議?

這是我試圖消耗「http://54.251.60.177/TMSOrdersService/TMSDetails.asmx」

這個Web服務的輸入值是準確的Web服務

FROM日期:01/01/2012

TODATE:07/07/2012

源頭參考

Webservice_.java

public class Webservice_ extends Activity 
{ 

public static String rslt=""; /** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Button b1=(Button)findViewById(R.id.button1); 
    final AlertDialog ad=new AlertDialog.Builder(this).create(); 

    b1.setOnClickListener(new OnClickListener() { 


public void onClick(View arg0) 
{ 

try 
{ 
EditText ed1=(EditText)findViewById(R.id.editText1); 
EditText ed2=(EditText)findViewById(R.id.editText2); 

int a=Integer.parseInt(ed1.getText().toString()); 
int b=Integer.parseInt(ed2.getText().toString()); rslt="START"; 

Caller c=new Caller(); 

c.FromDate=a; 
c.ToDate=b; 

c.ad=ad; 

c.join(); 
c.start(); 

while(rslt=="START") 
{ 
try { 
Thread.sleep(10); 

}catch(Exception ex) { 

} 
} ad.setTitle(+a +b); 
ad.setMessage(rslt); 

}catch(Exception ex) { 
ad.setTitle("Error!"); ad.setMessage(ex.toString()); 
} 
ad.show(); 
} }); 
}} 

CallSoap.java

public class CallSoap 
{ 
public final String METHOD_NAME = "GetTMSChart"; 
public final String NAMESPACE = "http://tempuri.org/"; 
public final String SOAP_ACTION = "http://tempuri.org/GetTMSChart"; 
public final String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx"; 

public CallSoap() 
{ 

} 
public String Call(int FromDate,int ToDate) 
{ 

SoapObject request = new SoapObject(NAMESPACE,SOAP_ACTION); 
PropertyInfo pi=new PropertyInfo(); 

pi.setName("FromDate"); 
pi.setValue(FromDate); 

pi.setType(Date.class); 
request.addProperty(pi); 

pi=new PropertyInfo(); 

pi.setName("ToDate"); 
pi.setValue(ToDate); 
pi.setType(Date.class); 
request.addProperty(pi); 

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

envelope.setOutputSoapObject(request); 

HttpTransportSE httpTransport = new HttpTransportSE(URL); 
Object response=null; 
try 
{ 
httpTransport.call(SOAP_ACTION, envelope); 
    response = envelope.getResponse(); 
} 
catch (Exception exception) 
{ 
response=exception.toString(); 
} 
return response.toString(); 
} 
} 

Caller.java

public class Caller extends Thread 

{ 
public CallSoap cs; 
public int FromDate,ToDate; 
protected AlertDialog ad; 

public void run() 
{ 
try 
{ 
cs=new CallSoap(); 
String resp=cs.Call(FromDate, ToDate); 

Webservice_.rslt=resp; 
} 
catch(Exception ex) 
{ 
Webservice_.rslt=ex.toString(); 
}  
} 
} 

感謝您的寶貴時間!..

+0

公共字符串調用(INT FROM日期,INT TODATE)應該是公共字符串調用(日期FROM日期,日期TODATE)或類似明智 –

回答

0

的核心代碼會是這樣的你javafile以下...

SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME); 
PropertyInfo pi=new PropertyInfo(); 
pi.setName("a"); 
pi.setValue(a); 
pi.setType(Integer.class); 
request.addProperty(pi); 
pi=new PropertyInfo(); 
pi.setName("b"); 
pi.setValue(b); 
pi.setType(Integer.class); 
request.addProperty(pi); 

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

envelope.setOutputSoapObject(request); 

Here是完整的一個,通過一個步驟產生相同的。

希望這會有所幫助。

最重要的是,你可以see此鏈接,

感謝, Jigar

+0

我已按照你的建議,我有一些新的問題,你能讓我清楚嗎? – Rohith

+0

是什麼問題? –

+0

其實我是通過輸入值作爲日期即(2012年1月1日和2012年7月7日),但我得到的問題作爲java.lang.NumberFormat異常 – Rohith

相關問題