0

如何通过 SOAP 方法传递两个参数以使用来自 android 的 Web 服务。我已经尝试过了,但我无法从 android 使用该 Web 服务。

建议?

这是我试图使用“http://54.251.60.177/TMSOrdersService/TMSDetails.asmx”的确切网络服务

此 Web 服务的输入值是

FromDate : 01/01/2012

截止日期 : 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();
}  
}

调用者.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();
}    
}
}

感谢您宝贵的时间!..

4

1 回答 1

1

核心代码将类似于您的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);

这里是完整的一步一步来制作相同的。

希望这可以帮助。

最重要的是,您可以看到此链接,

谢谢, 吉格

于 2012-09-10T10:51:16.117 回答