如何通過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();
}
}
}
感謝您的寶貴時間!..
公共字符串調用(INT FROM日期,INT TODATE)應該是公共字符串調用(日期FROM日期,日期TODATE)或類似明智 –