- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 android 的初学者,这里我有使用网络服务的 Activity :
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
GetBoundData val = new GetBoundData() {
};
PropertyInfo pi = new PropertyInfo();
pi.setName("GetBoundData");
pi.setValue(val);
pi.setType(GetBoundData.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
Marshal floatMarshal = new MarshalFloat();
envelope.addMapping(NAMESPACE, GetBoundData.class.getSimpleName(), GetBoundData.class);
floatMarshal.register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug =true;
TextView t = (TextView)this.findViewById(R.id.resultbox);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
System.out.println("aht requestDump is :"+androidHttpTransport.requestDump);
System.out.println("aht responseDump is :"+androidHttpTransport.responseDump);
} catch (Exception e) {
e.printStackTrace();
}
try {
Object result = (Object) envelope.bodyIn;
String s = result.toString();
t.setText(s);
} catch (ClassCastException e) {
// TODO Auto-generated catch block
e.printStackTrace();
t.setText("1");
}
在 GetBoundData 类中:
public abstract class GetBoundData implements KvmSerializable {
String Bound = "((-0.00021792948245596397, -0.0002648681402206421), (0.00021792948246868618, 0.0002648681402206421))";
String Zoom ="21";
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return Bound;
case 1:
return Zoom;
default:
return null;
}
}
public int getPropertyCount() {
return 2;//because you have 2 parameters
}
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Bound";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Zoom";
break;
default:break;
}
}
public void setval(String bound, String zoom) {
Bound = bound;
Zoom = zoom;
}
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
case 0:
Bound = (String)arg1;
break;
case 1:
Zoom = (String)arg1;
break;
default:
break;
}
}
这是 web 服务 xml
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="GetBoundData">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Bound" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Zoom" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetBoundDataResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetBoundDataResult" type="tns:ArrayOfAnyType"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfAnyType">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="anyType" nillable="true"/>
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
这里是网络服务示例:
要求:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetBoundData xmlns="http://tempuri.org/">
<Bound>string</Bound>
<Zoom>string</Zoom>
</GetBoundData>
</soap:Body>
</soap:Envelope>
回复:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetBoundDataResponse xmlns="http://tempuri.org/">
<GetBoundDataResult>
<anyType />
<anyType />
</GetBoundDataResult>
</GetBoundDataResponse>
</soap:Body>
</soap:Envelope>
但是显示这个:
SoapFault - faultcode: 'soap:Server'
faultstring: 'Server was unable to process request. ---> Object reference not set to an
instance of an object.' faultactor: 'null' detail: org.kxml2.kdom.Node@44efb360
我将 soapobject 与 getresponse() 一起使用,但发生了错误
最佳答案
那是因为你有复杂类型(即对象)而你只是添加“简单类型”属性。
检查我的答案here ,我详细解释了需要做什么。
您还必须创建匹配复杂类型的本地类,这些本地类应该实现 kvmserializable,例如:
<s:element name="GetBoundData">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Bound" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Zoom" type="s:string"/>
</s:sequence>
</s:complexType>
意味着在网络服务上,存在一个名为“GetBoundData”的类。因此,由于您使用 ksoap2 手动构建 soap 信封,因此您必须在应用程序中创建这样一个类,实现 kvmserializable(这是一个 ksoap2 序列化接口(interface)):
public class GetBoundData implements KvmSerializable {
String Bound;
String Zoom;
@Override
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return Bound;
case 1:
return Zoom;
default:
return null;
}
}
@Override
public int getPropertyCount() {
return 2;//because you have 2 parameters
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Bound";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Zoom";
break;
default:break;
}
}
@Override
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
case 0:
Bound = (String)arg1;
break;
case 1:
Zoom = (String)arg1;
break;
default:
break;
}
}
这就是您在本地为服务器上的类(对象,即复杂类型)构建匹配项的方式。然后您必须添加必要的属性、构建信封、添加映射和编码 并发送请求。这些步骤都在我上面提到的链接中进行了解释。
更新我将向您解释这些是什么:
<wsdl:message name="GetBoundDataSoapIn">
<wsdl:part name="parameters" element="tns:GetBoundData"/>
</wsdl:message>
什么时候是wsdl:message 表示它是web服务需要的一个函数。它有 ,这意味着它需要一个 GetBoundData 类型的参数,它不是原始类型,实际上它是一个复杂类型(对象)。
所以这里是步骤:
1- 你必须编写复杂类型 GetBoundData 的本地表示,即类(我已经在上面写过了)
2- 在您的应用程序中,您必须创建(由您决定)一个函数,该函数将调用与 Web 服务上的“GetBoundDataSoapIn”相关的函数。所以创建一个名字有意义的函数是个好主意,比如:
public GetBoundData getBoundData()
{
try
{
SoapObject sobj = new SoapObject(YOUR_NAMESPACE,THE_METHOD_NAME);
//------------------------------------------------------------------------------
// GetBoundData :adding property
// <wsdl:message name="GetBoundDataSoapIn">
// <wsdl:part name="parameters" element="tns:GetBoundData"/>
// </wsdl:message>
// GetBoundData has two params:
// <s:element minOccurs="0" maxOccurs="1" name="Bound" type="s:string"/>
// <s:element minOccurs="0" maxOccurs="1" name="Zoom" type="s:string"/>
//
//--------------------------------------------------------------------------
//--------------
// GetBoundData
//--------------
PropertyInfo pi = new PropertyInfo();
pi.setName("GetBoundData");
pi.setValue(Whatever_value_your_supposed_to_put);// these values are "Bound" And "Zoom" , they're supposed to be gotten in your app somewhere
pi.setType(GetBoundData.class);
sobj.addProperty(pi);
//------------------------------
// START BUILDING SOAP ENVELOPE
//------------------------------
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(sobj);
//---------------------------------------------------------------------------------------
// MAPPINGS:
//---------------------------------------------------------------------------------------
soapEnvelope.addMapping(YOUR_NAMESPACE, GetBoundData.class.getSimpleName(), GetBoundData.class);
//---------------------------------------------------------------------------------------
// MARSHALLING:
//---------------------------------------------------------------------------------------
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(soapEnvelope);
AndroidHttpTransport aht = new AndroidHttpTransport(YOUR_URL);
aht.debug = true;
try
{
aht.call(YOUR_ACTION, soapEnvelope);
//Importat Outputs to check how the request/Response looks like.. Check Logcat to find these outputs
System.out.println("aht requestDump is :"+aht.requestDump);
System.out.println("aht responseDump is :"+aht.responseDump);
return soapEnvelope.getResponse();
}
catch (Exception e)
{
e.printStackTrace();
return "Exception: " + e.getMessage()+" message IS :" +e.getMessage()+" localizedmessage is :"+e.getLocalizedMessage();
}
}
catch(Exception ex)
{
ex.printStackTrace();
return "Exception: " + ex.getMessage();
}
}
}
所以检查 logCat 以查看请求和响应的形状,你会看到是否必须获取响应并解析它才能使用它,我不确定你的响应是什么,但在我的情况下是一个多维数组,所以我不得不使用 Java 功能来解析它。
至于:
<wsdl:message name="GetBoundDataSoapOut">
<wsdl:part name="parameters" element="tns:GetBoundDataResponse"/>
</wsdl:message>
这只是告诉您网络服务发回了一个响应。
关于android soapfault 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8968620/
我试图从 PHP SoapServer 返回一个 SoapFault,但我坚持创建正确的响应格式。 处理异常时,我返回: $detail = "message"; return new SoapFau
我是 android 的初学者,这里我有使用网络服务的 Activity : SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
我得到了这个我不明白的 SoapFault。调用下面的函数 codewordStemExists(),应该会创建一个连接到已启动并正在运行的 SoapServer 的 SoapClient(没有从服务
我是 PHP 异常处理和 SOAP 的新手。出于某种原因,我无法捕捉到 SoapFault。我不知道为什么。 soap 服务器不是我的。 try { $contact_id = $objSoa
我正在尝试获取此 soap 错误的“详细信息”中的值,但我还没有找到任何方法。 服务器响应: SOAP-ENV:Client Many Erro
我正在将我的 Android 代码与 Webservice 连接以检索数据。我总是得到: SoapFault - faultcode: 'a:InternalServiceFault' faults
运行两个服务器,服务器 1:是一个 Soap 客户端,服务器 2:是一个 Soap 服务器 我从服务器 1 向服务器 2 发送一个信封,其中包含以下参数: client_hash(字符串),唯一代码(
我目前正在尝试使用 php-ews,但是我不知道 soap 有一些问题,下面是错误。 Fatal error: Uncaught SoapFault exception: [VersionMismat
我正在连接到网络服务以获取一些数据。我有大约 20 万个作业的请求队列,一个工作人员正在处理它。处理时间为每秒 2-3 次调用。在大约 500-1000 次调用后,它开始收到 SoapFault 异常
我正在创建一个 WCF web 服务,它的请求/响应应该只签名。 为此,我在 ServiceContract 属性上设置了 ProtectionLevel = ProtectionLevel.Sign
假设我的文件中有以下 xml 负载 ns2:Server some Error 04 SimiError 如何将其解码到 Soap
尝试使用 soap 服务将数据发送到 sql 数据库。但我的网站只加载 30 秒后出现此错误: Warning: Uncaught SoapFault exception: [HTTP] Error
我可以在 Savon 日志中看到我的 SOAP 错误包含如下 XML: 666some evil error 有谁知道如何从响应中解析错误代码和描述?很抱歉,如果这是一个愚蠢的问题,但我已经尝试了所有
为什么我可以设置一个faulString,但不能在SOAPFault 中设置一个自定义错误代码?当我抛出异常时,文本“Code X”没有出现在 SoapFaultException 中。有人能告诉我为
我的 SOAP 解决方案出现问题。有时我会收到以下错误消息: Function (functionA) is not a valid method for this service 8 个月后编辑虽然
有时无法调用网络服务。 这个问题一直都在发生。 可能是什么问题? Error: SoapFault exception: [HTTP] Could not connect to host in
我要集成 eway token 支付集成,但我正面临这个问题。 SoapFault exception: [HTTP] Bad Request wsdl文件在这里 https://www.eway.c
我在 java 中使用 axis2 创建了用于将两个数字相乘的 web 服务.. wsdl文件是 - Please Type your service description here -
我们的java应用程序使用glassfish 2.1作为服务器,我将ear文件部署到glassfish上并使用soapUI发送请求,并期望在响应中返回soapFault。但我得到了“HTTP Stat
我正在尝试提取 Web 服务的soapFault 响应的错误代码和错误消息,但收到 ClasscasrException : 下面是网络服务响应: 2015-
我是一名优秀的程序员,十分优秀!