如何通过SOAP方法传递两个参数来从android使用Web服务。 我试过了,但我无法从Android上使用该Web服务。
建议?
这是我尝试使用的确切网络服务“http://54.251.60.177/TMSOrdersService/TMSDetails.asmx”
此Web服务的输入值为
FromDate: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 :(得分: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