我想从我的Ksoap客户端发送一个复杂的对象到我的web服务。这是我的班级类别的一个对象。代码是基于本教程的例子:KSoap2和KvmSerializable - 如何发送像Stringarrays复杂的对象
的web服务正在运行,并且所述WSDL文件示出了类别对象。但是,如果我发送一个类别对象,以我的肥皂web服务,以下错误显示出来:
试图调用服务方法 getCategoryObject org.apache.axis2.AxisFault发生
[错误]异常:不明类型 { http://ws.chathura.com}类别Logcat显示以下内容:06-12 11:08:57.576:W/System.err(777):SoapFault - faultcode: 'soapenv:Server'faultstring:'未知键入 {http://ws.chathura.com}分类” faultactor: '空' 的细节: [email protected]
这是我的Java web服务在Tomcat 7捉迷藏:
package com.chathura.ws;
import java.util.Vector;
public class HelloWorldWS
{
public Category getCategoryObject(Category obj)
{
Category C1 = new Category();
C1.setCategoryId(1);
C1.setDescription("server desc");
C1.setName("server Name");
System.out.println(obj.getCategoryId());
return C1;
}
}
这是在Web服务器上我的分类类别:
package com.chathura.ws;
public class Category {
private int CategoryId;
private String Name;
private String Description;
/**
* @return the categoryId
*/
public int getCategoryId() {
return CategoryId;
}
/**
* @param categoryId the categoryId to set
*/
public void setCategoryId(int categoryId) {
CategoryId = categoryId;
}
/**
* @return the name
*/
public String getName() {
return Name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
Name = name;
}
/**
* @return the description
*/
public String getDescription() {
return Description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
Description = description;
}
}
这是WSDL文件:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
Please Type your service description here
而且这是我的Android测试应用程序:
package de.bachelor.marcel;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class WSClientKomplexeObjekteActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.chathura.com/getCategoryObject";
private static final String METHOD_NAME = "getCategoryObject";
private static final String NAMESPACE = "http://ws.chathura.com";
private static final String URL = "http://192.168.2.102:8080/WebProject_KomplexObjects/services/HelloWorldWS?wsdl";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
/*
* Create Category with Id to be passed as an argument
*
* */
Category C = new Category();
C.CategoryId = 1;
C.Description = "Das ist die Beschreibung";
C.Name = "ObjektName";
/*
* Set the category to be the argument of the web service method
*
* */
PropertyInfo objekt = new PropertyInfo();
objekt.setName("obj");
objekt.setValue(C);
objekt.setType(C.getClass());
Request.addProperty(objekt);
/*
* Set the web service envelope
*
* */
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(Request);
envelope.addMapping(NAMESPACE, "Category",new Category().getClass());
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
/*
* Call the web service and retrieve result ... how luvly <3
*
* */
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
C.CategoryId = Integer.parseInt(response.getProperty(0).toString());
C.Name = response.getProperty(1).toString();
C.Description = (String) response.getProperty(2).toString();
TextView tv = (TextView)findViewById(R.id.textview1);
tv.setText("CategoryId: " +C.CategoryId + " Name: " + C.Name + " Description " + C.Description);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
这里是来自Android客户端的分类类别:
package de.bachelor.marcel;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class Category implements KvmSerializable
{
public int CategoryId;
public String Description;
public String Name;
public Category(){}
public Category(int categoryId, String description, String name)
{
CategoryId = categoryId;
Name = name;
Description = description;
}
@Override
public Object getProperty(int arg0)
{
switch(arg0)
{
case 0:
return CategoryId;
case 1:
return Description;
case 2:
return Name;
}
return null;
}
@Override
public int getPropertyCount()
{
return 3;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2)
{
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Description";
break;
case 2:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Name";
break;
default:break;
}
}
@Override
public void setProperty(int arg0, Object arg1)
{
switch(arg0)
{
case 0:
CategoryId = Integer.parseInt(arg1.toString());
break;
case 1:
Description = arg1.toString();
break;
case 2:
Name = arg1.toString();
break;
default:
break;
}
}
}
+0
你在措辞问题上的努力是好的我有类似的问题,但是什么是解决方案..请帮助你如何解决它 –
+0
你能请共享解决方案吗?我现在面临同样的问题 –
+0
@Florian E:请。请参阅此链接[http://stackoverflow.com/questions/19198017/pass-arraylist-data-into-soap-web-service-in-android](http://stackoverflow.com/questions/19198017/pass-arraylist Android中的数据到SOAP网页服务)我必须传递数组的值哪些内容3参数,所以我怎么能传递给SOAP服务任何想法? –