2010-04-08 34 views
3

我正在嘗試爲android創建一個web服務客戶端,但我被卡住了真的很糟糕附加的是我的代碼和WSDL文件。請幫助Android上的SOAP web客戶端

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 

package org.me.androidapplication1; 

import android.app.Activity; 

import android.os.Bundle; 

import android.widget.TextView; 

import java.io.IOException; 

import java.util.logging.Level; 

import java.util.logging.Logger; 

import org.ksoap2.SoapEnvelope; 

import org.ksoap2.serialization.SoapObject; 

import org.ksoap2.serialization.SoapPrimitive; 

import org.ksoap2.serialization.SoapSerializationEnvelope; 

import org.ksoap2.transport.AndroidHttpTransport; 

import org.xmlpull.v1.XmlPullParserException; 


/** 
* 
* @author bansal 
*/ 
public class MainActivity extends Activity { 



private String SOAP_ACTION = "http://src/getNews"; 

private String METHOD_NAME = "getNews"; 

private String NAMESPACE = "http://src/"; 

private static final String URL ="http://128.205.201.202:8080/RssService 
/RssServiceService?WSDL"; 

/** Called when the activity is first created. */ 
@Override 

public void onCreate(Bundle icicle) { 

super.onCreate(icicle); 


TextView tv = new TextView(this); 

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

request.addProperty("ticker","NASDAQ:INFY"); 

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

envelope.setOutputSoapObject(request); 

AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); 

try { 

androidHttpTransport.call(SOAP_ACTION, envelope); 

SoapPrimitive p = (SoapPrimitive) envelope.getResponse(); 

tv.setText("Response " + p); 


} catch (Exception ex) { 


ex.printStackTrace(); 

} 


setContentView(tv); 


// ToDo add your GUI initialization code here 

} 

} 

感謝

+0

我不確定名稱空間,URL和SOAP_ACTION的值是否正確。你可以看看我的WSDL,並告訴他們是否是正確的 - <定義的targetNamespace = 「HTTP:// SRC /」 NAME = 「RssServiceService」> - - - <消息名稱= 「getNews」> <部件名稱= 「parameters」element =「tns:getNews」/> - – 2010-04-09 02:09:22

回答

0

移動Web服務調用出來的onCreate,做它在另一個線程。你不想在onCreate中進行任何密集的事情,否則它會掛起活動的創建和顯示。

+0

我不確定是否t他的變量值是正確的。你可以檢查,如果他們是根據我WSDL <定義的targetNamespace = 「HTTP:// SRC /」 NAME = 「RssServiceService」> - - - <消息名稱= 「getNews」> <部件名稱= 「參數」 元素= 「TNS:getNews」/> – 2010-04-09 02:16:16

0

BANSAL

這個Web服務:http://128.205.201.202:8080/RssService /RssServiceService WSDL

我嘗試使用SOAP UI工具,但越來越看到Web服務錯誤消息說:錯誤導入WSDL文件

所以你只需要嘗試另一個工作鏈接。 &首先從SOAP UI工具中檢出響應。 &然後根據你的代碼改變後。在方法名稱中進行更改。再次運行它。

您可以使用正在運行的WSDL文件:http://ws.oag.com/OAGFlightStatusInformation.asmx?WSDL來測試您的代碼。 它可能會爲你工作。