- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将一个复杂的对象从我的 Ksoap 客户端发送到我的 Web 服务。它是我的类别类别的一个对象。该代码基于本教程的示例:
http://seesharpgears.blogspot.de/2010/10/ksoap-android-web-service-tutorial-with.html
Web 服务正在运行,并且 WSDL 文件显示类别对象。但是,如果我将类别对象发送到我的肥皂网络服务,则会显示以下错误:
[ERROR] Exception occurred while trying to invoke service method getCategoryObject org.apache.axis2.AxisFault: Unknow type {http://ws.chathura.com}Category Logcat shows up the following: 06-12 11:08:57.576: W/System.err(777): SoapFault - faultcode: 'soapenv:Server' faultstring: 'Unknow type {http://ws.chathura.com}Category' faultactor: 'null' detail: org.kxml2.kdom.Node@4054a528
这是我在 Tomcat 7 上运行的 Java Web 服务:
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.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://ws.chathura.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax21="http://ws.chathura.com/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://ws.chathura.com">
<wsdl:documentation>Please Type your service description here</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.chathura.com/xsd">
<xs:complexType name="Category">
<xs:sequence>
<xs:element minOccurs="0" name="categoryId" type="xs:int"/>
<xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:ax22="http://ws.chathura.com/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.chathura.com">
<xs:import namespace="http://ws.chathura.com/xsd"/>
<xs:element name="getCategoryObject">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="obj" nillable="true" type="ax21:Category"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getCategoryObjectResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax21:Category"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="getCategoryObjectRequest">
<wsdl:part name="parameters" element="ns:getCategoryObject"/>
</wsdl:message>
<wsdl:message name="getCategoryObjectResponse">
<wsdl:part name="parameters" element="ns:getCategoryObjectResponse"/>
</wsdl:message>
<wsdl:portType name="HelloWorldWSPortType">
<wsdl:operation name="getCategoryObject">
<wsdl:input message="ns:getCategoryObjectRequest" wsaw:Action="urn:getCategoryObject"/>
<wsdl:output message="ns:getCategoryObjectResponse" wsaw:Action="urn:getCategoryObjectResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldWSSoap11Binding" type="ns:HelloWorldWSPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getCategoryObject">
<soap:operation soapAction="urn:getCategoryObject" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="HelloWorldWSSoap12Binding" type="ns:HelloWorldWSPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getCategoryObject">
<soap12:operation soapAction="urn:getCategoryObject" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="HelloWorldWSHttpBinding" type="ns:HelloWorldWSPortType">
<http:binding verb="POST"/>
<wsdl:operation name="getCategoryObject">
<http:operation location="getCategoryObject"/>
<wsdl:input>
<mime:content type="text/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldWS">
<wsdl:port name="HelloWorldWSHttpSoap11Endpoint" binding="ns:HelloWorldWSSoap11Binding">
<soap:address location="http://localhost:8080/WebProject_KomplexObjects/services/HelloWorldWS.HelloWorldWSHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="HelloWorldWSHttpSoap12Endpoint" binding="ns:HelloWorldWSSoap12Binding">
<soap12:address location="http://localhost:8080/WebProject_KomplexObjects/services/HelloWorldWS.HelloWorldWSHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="HelloWorldWSHttpEndpoint" binding="ns:HelloWorldWSHttpBinding">
<http:address location="http://localhost:8080/WebProject_KomplexObjects/services/HelloWorldWS.HelloWorldWSHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
这是我的 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;
}
}
}
最佳答案
尝试使用
private static final String NAMESPACE = "http://ws.chathura.com/xsd";
在您的 Android Activity 中,并将 getter 和 setter 添加到客户端中的 Category
类中。
关于java - KSoap2 和 KvmSerialized - 如何发送复杂的对象,如 Stringarrays,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10999763/
我的 kSOAP 网络服务将 xml 返回为这种格式我如何从中获取 country_name anyType{country=anyType{country_name=Egypt; };
我能够使用 ksoap2 获取复杂的类响应,现在我得到的响应是 xml 形式 任何人都可以帮我解决如何解析这个 Ksoap 响应吗?我已经在论坛上阅读了为它添加映射的内容,我也添加了映射。我可以使用
我一直在使用 Android 版 KSOAP 发送包含 6 个元素的 SOAP 请求,最后一个元素是一个值数组。这是代码... PropertyInfo properties[] = n
我在我的 Android 应用程序中使用 KSoap。我的应用程序使用 Web 服务与服务器通信。我找到了一个 KSoap wev 服务客户端的代码示例。在示例中,客户端使用以下代码与服务器进行通信
我正在使用 KSOAP2 调用 Web 服务。我收到了回复,但该回复中的特殊字符未正确显示。 我怎样才能改变它? 编辑: 以下代码负责发送和接收数据: package org.ksoap2.trans
我正在使用 Android ksoap2 库来使用 SOAP 网络服务。 请求中的一个节点看起来像.. //some more nodes .............
我有 ksop 请求。我揉出来的是 asdfdsafdsfasdfdsa
我正在使用支持超时的 ksoap2 2.5.4(在 Android 2.2 上)。我正在使用 Apache 2.2.16 来处理我的请求。一切正常,但当我关闭我的 Apache(或断开运行 Apach
帮帮我,我花了大约 3 周的时间搜索整个 www,但无法正常工作! 我有一个 WS,只想让我的应用程序有响应。但不幸的是,我在更正所有内容后总是得到以下错误! 08-09 15:29:30.930:
当向 soap 对象添加属性时无法指定其类型....我需要整数但它总是将其设置为“d:string”1312191347这是我添加属性(property)的方式: SoapObject _client
我在尝试使用 kSOAP2 在 Android 中使用 ColdFusion SOAP 服务时遇到了一个问题。这是我的 java 代码,用于调用我在 ColdFusion 中编写的测试方法(它只返回一
我正在尝试通过 kSOAP(直接从 Google 下载并包含“.jar”)调用公共(public) Web 服务 (w3schools.com/webservices/tempconvert.asmx
有没有人有使用 kSOAP 包的良好的复杂对象编码示例? 最佳答案 虽然这个例子不是可编译的和完整的,但基本思想是有一个类告诉 kSOAP 如何将 XML 标记转换为对象(即 readInstance
我正在通过 SOAP 发送多个 PDF 文件,Android 客户端将接收这些文件。但是当收到 SOAP 响应时,它会抛出 OutOfMemoryException。 我想知道它是否是 kSOAP 或
我正在使用 Android 中的 Ksoap 访问 .net 网络服务。 wsdl 的格式是这样的 Date1 Date2 我对 DateTo 使用相同的 addPropert
我不知道为什么我不能得到这个?......也许我遗漏了什么或者我太笨了 我想尝试从 Android 应用程序调用网络服务 现在要做到这一点,发现适用于 Android 的 kSOAP 2 是所需的库
我正在使用 ksoap2 (ksoap2-android-assembly-3.0.0-RC.1-jar-with-dependencies.jar) 与我的 android 应用通信在 jboss
我在下面显示的代码中使用 soap 访问 Web 服务并收到以下错误,我需要帮助来理解: SoapFault - faultcode: 'soap:Server' faultstring: 'Syst
我希望生成像这样的 soap 请求: - - Connect -
马上,这是我的 Soap 调用实现,减去不相关的位。 public class MySoapClient implements AbstractSoapClient { private Str
我是一名优秀的程序员,十分优秀!