我想在Android应用程序中调用soap web服务,它需要一个枚举值作为参数,它是一个标志枚举。如何从android app中将一些值作为标志枚举传递给此Web服务方法?
我使用Ksoap来拨打肥皂服务。
它的网络服务方法:
[WebMethod]
public ReceptionCommitResult CommitReceiption(some parameters, EnumName myEnum)
{
//mehod body
}
和web服务枚举:
[Flags]
public enum EnumName
{
One= 0,
Two = 1,
Three = 2,
Four = 4,
Five = 8,
}
最后我调用服务的代码:
SoapObject soapObj = new SoapObject(ServiceUtil.WSDL_TARGET_NAMESPACE, "RCI");
AttributeInfo attrInfo = new AttributeInfo();
attrInfo.setName("myEnum");
attrInfo.setValue("");
attrInfo.setType(EnumName.class);
soapObj.addAttribute(attrInfo);
SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
_envelope.skipNullProperties = false;
_envelope.implicitTypes = true;
_envelope.dotNet = true;
_envelope.setOutputSoapObject(_client);
_envelope.bodyOut = _client;
_envelope.addMapping(WSDL_TARGET_NAMESPACE, "RCI",new MyClassObject().getClass());
HttpTransportSE httpTransport1 = new HttpTransportSE(ServiceUtil.SOAP_ADDRESS, 60000000);
httpTransport1.debug = true;
httpTransport1.call(ServiceUtil.SOAP_ACTION, _envelope);
答案 0 :(得分:0)
在C#中,枚举标志通常在内部表示为32/64位整数。所以通常你只需要将你的枚举值转换为整数值并传递给webservice。
也许你需要尝试这样的事情:
AttributeInfo attrInfo = new AttributeInfo();
attrInfo.setName("myEnum");
attrInfo.setValue("5"); //For a value of Two | Four
attrInfo.setType(EnumName.class);
soapObj.addAttribute(attrInfo);
答案 1 :(得分:0)
你可以像这样使用它:
public enum EnumName {
One(1),Two(2),Three(3);
public final int value;
MyEnum(final int value) {
this.value = value;
}
}
获取值将是:
EnumName e = EnumName.One;
int value = e.value; //= 1
String name = e.name(); // = "One"
拥有on属性:
EnumName e = EnumName.One;
AttributeInfo attrInfo = new AttributeInfo();
attrInfo.setName(e.name());
attrInfo.setValue(e.value); //For a value of Two | Four
attrInfo.setType(EnumName.class);
soapObj.addAttribute(attrInfo);
还有一个类似的问题并且通过这种方式解决它也请看一看;