传递两个参数消耗从Android的Web服务 [英] Passing two parameters to consume a web service from android

查看:158
本文介绍了传递两个参数消耗从Android的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过两个参数的方法SOAP消耗从Android的Web服务。
我都试过了,但我无法从Android消耗的Web服务。

How to pass two parameters to consume a web service from android by the method SOAP. I have tried,but i am unable to consume that web service from android.

建议?

这是我试图消耗确切的Web服务http://54.251.60.177/TMSOrdersService/TMSDetails.asmx

This is the exact web service which i am trying to consume "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx"

该Web服务的输入值

寄件者:01/01/2012

FromDate : 01/01/2012

TODATE:07月07日

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

感谢您的precious时间!..

Thanks for your precious time!..

推荐答案

核心code会像在下面的javafile ...

The core code would be something like following in your 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 is complete one by one step to produce the same.

希望这有助于。

在那你可以<顶级href=\"http://www.android.net/forum/beginning-developers/78662-how-call-net-asmx-webservice-android.html\"相对=nofollow> 看到这个链接,

On top of that you can see this link,

谢谢,
Jigar

Thanks, Jigar

这篇关于传递两个参数消耗从Android的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆