我希望生成一个肥皂请求,例如:
<soapenv:Body>
-
<Perform xmlns="eras.in">
-
<request>
<ActionName>Connect</ActionName>
-
<Input xmlns:ns1="eras.in" xsi:type="ns1:Record">
<ns1:EntityName>Credential</ns1:EntityName>
-
<ns1:Fields>
-
<ns1:Field>
<ns1:Key>DomainName</ns1:Key>
<ns1:Value xsi:type="ns2:guid"
xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/">Check2</ns1:Value>
</ns1:Field>
-
<ns1:Field>
<ns1:Key>UserName</ns1:Key>
<ns1:Value xsi:type="ns3:guid"
xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/">utsav</ns1:Value>
</ns1:Field>
-
<ns1:Field>
<ns1:Key>Password</ns1:Key>
<ns1:Value xsi:type="ns4:guid"
xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/">xxxxx</ns1:Value>
</ns1:Field>
</ns1:Fields>
</Input>
</request>
</Perform>
</soapenv:Body>
但我能够生成类似的东西:
<v:Body>
<Perform xmlns="eras.in">
<request i:type="n0:ActionRequest" xmlns:n0="eras.in">
<ActionName i:type="d:string">Connect</ActionName>
<sessionId i:null="true" />
<Input i:type="n0:Record">
<EntityName i:type="d:string">Credential</EntityName>
<RecordId i:null="true" />
<Fields i:type="n0:Fields">
<Field i:type="n0:Field">
<Key i:type="d:string">DomainName</Key>
<Value i:type="d:string">Check2</Value>
</Field>
<Field i:type="n0:Field">
<Key i:type="d:string">UserName</Key>
<Value i:type="d:string">utsav</Value>
</Field>
<Field i:type="n0:Field">
<Key i:type="d:string">Password</Key>
<Value i:type="d:string">xxx</Value>
</Field>
</Fields>
</Input>
</request>
</Perform>
</v:Body>
在服务器上,当我检查时,我看到 Fields 数组是一个空对象。
有人可以帮忙吗?
我怀疑在服务器端对象中有一个名为 Fields 的字段类型数组。而我发送一个名为 Fields 的矢量对象。这会导致问题吗?
还是因为字段标签缺少命名空间前缀?
谢谢并恭祝安康。
我的Java代码是:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
ActionRequest ERequest = new ActionRequest();
ERequest.setActionName("Connect");
Record r = new Record();
r.setEntityName("Credential");
Fields fs = new Fields();
fs.add(new Field("DomainName","Check2"));
fs.add(new Field("UserName","utsav"));
fs.add(new Field("Password","xxxx"));
r.setFields(fs);
ERequest.setInput(r);
request.addProperty("request",ERequest);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.setAddAdornments(false);
envelope.implicitTypes = true;
envelope.addMapping(NAMESPACE, "ActionRequest", new ActionRequest().getClass());
envelope.addMapping(NAMESPACE, "Record", new Record().getClass());
envelope.addMapping(NAMESPACE, "Field", new Field().getClass());
ActionRequest.java:
package com.example.eat;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class ActionRequest implements KvmSerializable {
private java.lang.String ActionName;
private java.lang.Object input;
private java.lang.String sessionId;
public java.lang.String getActionName() {
return ActionName;
}
public void setActionName(java.lang.String actionName) {
this.ActionName = actionName;
}
public java.lang.Object getInput() {
return input;
}
public void setInput(java.lang.Object input) {
this.input = input;
}
public java.lang.String getSessionId() {
return sessionId;
}
public void setSessionId(java.lang.String sessionId) {
this.sessionId = sessionId;
}
public ActionRequest() {
}
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
switch (arg0) {
case 0:
return ActionName;
case 1:
return sessionId;
case 2:
return input;
default:
break;
}
return null;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 3;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo info) {
// TODO Auto-generated method stub
switch (arg0) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "ActionName";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "sessionId";
break;
case 2:
info.type = Object.class;
info.name = "Input";
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
// TODO Auto-generated method stub
switch (index) {
case 0:
this.ActionName =value.toString();
break;
case 1:
this.sessionId = value.toString();
break;
case 2:
this.input = value;
default:
break;
}
}
}
记录.Java:
package com.example.eat;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class Record implements KvmSerializable {
private java.lang.String EntityName;
private java.lang.String RecordId;
private Fields Fields1 = new Fields();
//Field[] fs = new Field[0];
public com.example.eat.Fields getFields() {
return Fields1;
}
public void setFields(Fields f) {
this.Fields1 = f;
}
public java.lang.String getEntityName() {
return EntityName;
}
public void setEntityName(java.lang.String entityName) {
this.EntityName = entityName;
}
public java.lang.String getRecordId() {
return RecordId;
}
public void setRecordId(java.lang.String recordId) {
this.RecordId = recordId;
}
public Record() {
}
public Record(
java.lang.String entityName,
Fields fields,
java.lang.String recordId) {
this.EntityName = entityName;
this.Fields1 = fields;
this.RecordId = recordId;
}
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
switch (arg0) {
case 0:
return EntityName;
case 1:
return RecordId;
case 2:
return Fields1;
default:
break;
}
return null;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 3;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
// TODO Auto-generated method stub
switch (index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "EntityName";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "RecordId";
break;
case 2:
info.type = this.Fields1.getClass();
info.name = "Fields";
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
// TODO Auto-generated method stub
if(null == value)
value = "";
switch (index) {
case 0:
EntityName = value.toString();
break;
case 1:
RecordId= value.toString();
break;
case 2:
Fields1= (Fields) value;
break;
}
}
}
字段.java
package com.example.eat;
import java.util.Hashtable;
import java.util.Vector;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class Fields extends Vector <Field> implements KvmSerializable{
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
return this.get(arg0);
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return this.size();
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
// TODO Auto-generated method stub
arg2.name = "Field";
// arg2.type = PropertyInfo.STRING_CLASS;
arg2.type = new Field().getClass();
}
@Override
public void setProperty(int arg0, Object arg1) {
// TODO Auto-generated method stub
this.add((Field)arg1);
}
}
字段.java:
package com.example.eat;
import java.util.Hashtable;
import java.util.Vector;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
/**
* Field.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/
public class Field implements KvmSerializable {
private java.lang.String key;
private java.lang.Object value;
public Field(String key, String value) {
// TODO Auto-generated constructor stub
this.key=key;
this.value=value;
}
public Field() {
// TODO Auto-generated constructor stub
}
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
switch (arg0){
case 0:
return key;
case 1:
return value;
default:
return null;
}
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 2;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
// TODO Auto-generated method stub
switch (index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Key";
break;
case 1:
info.type = Object.class;
info.name = "Value";
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
// TODO Auto-generated method stub
if(null == value)
value = "";
switch (index) {
case 0:
key = value.toString();
break;
case 1:
this.value = value;
break;
}
}
}