2012-12-22 43 views
2

每當我上傳一個新的Object時,它向數據庫提交一個空對象並忽略我設置的所有參數。在android中使用kso​​ap2上傳的空物體

下面是Android的一面:

public void createGroupServ(String groupName) 
{ 
    request = new SoapObject(NAMESPACE, "createGroup"); 

    Group gr = new Group(); 
    gr.setGroupId(1L); 
    gr.setGroupName("xxxx"); 
    gr.setUsers(null); 

    PropertyInfo object = new PropertyInfo(); 
    object.setName("arg0"); 
    object.setValue(gr); 
    object.setType(gr.getClass()); 
    request.addProperty(object); 

    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = false; 
    envelope.setOutputSoapObject(request); 
    envelope.addMapping(NAMESPACE, "group", new Group().getClass()); 

    androidHttpTransport = new HttpTransportSE(URL); 
    androidHttpTransport.debug = true; 

}

和域類組:

public class Group implements KvmSerializable { 
    private long groupId; 
    private String groupName; 
    private List<User> users = null; 

...setter and getters ... 
} 

我的WSDL的xml:

<xs:complexType name="group"> 
<xs:sequence> 
<xs:element name="groupId" type="xs:long"/> 
<xs:element name="groupName" type="xs:string" minOccurs="0"/> 
<xs:element name="users" type="tns:user" nillable="true" minOccurs="0" maxOccurs="unbounded"/> 
</xs:sequence> 
</xs:complexType> 

<xs:complexType name="createGroup"> 
<xs:sequence> 
<xs:element name="arg0" type="tns:group" minOccurs="0"/> 
</xs:sequence> 
</xs:complexType> 

爲什麼它沒有按任何意見上傳整個對象t與組名參數?

回答

0

OK,我已經解決了這個問題。我並沒有實現KvmSerializable接口的方法 -

public Object getProperty 
public int getPropertyCount 
public void getPropertyInfo 
public void setProperty 

可以在這裏找到: http://seesharpgears.blogspot.co.uk/2010/10/ksoap-android-web-service-tutorial-with.html

此外,我做我的SOAP對象請求作爲單獨的一類,因爲它沒有在MainActivity工作爲了我。

+1

你可能會得到android.os.NetworkOnMainThreadException.Try在asynctask中調用你的soap對象請求,或者在你的主要活動中使用這個代碼。 'StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()。permitAll()。build(); StrictMode.setThreadPolicy(policy);' – mjosh

2

使用此

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
request.addproperty("arg0",gr); 

也不要忘了在方法中添加此 -

void customMethod(@WebParam(name = "arg0")String arg0) 
+0

謝謝,但沒有任何區別,相同的結果 - 上傳空對象。 – alex

+0

首先通過調試您的WebService來檢查值是否到達服務器。如果確實如此,請發佈您的Web服務的日誌控制檯。 – mjosh

相關問題