简体   繁体   中英

How to pass value to flag enum parameter in Soap service (ASMX service) From android app

I wanna call a soap web service in an android app which it's need a enum value as parameter which it's a flag enum. How can I pass some value as a flag enum to this web service method from android app?

I use Ksoap for calling soap service.

It's web service method:

[WebMethod]
    public ReceptionCommitResult CommitReceiption(some parameters, EnumName myEnum)
    {
        //mehod body
    }

and web service enum:

[Flags]
public enum EnumName 
{
    One= 0,
    Two = 1,
    Three = 2,
    Four = 4,
    Five = 8,

}

finally me code for calling service:

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);

In C# an enum flag is usually represented as 32/64 bit integer internally. So usually you only need to cast your enum value to a integer value and pass to webservice.

Maybe you need to try something like this:

AttributeInfo attrInfo = new AttributeInfo();
attrInfo.setName("myEnum");
attrInfo.setValue("5");  //For a value of Two | Four
attrInfo.setType(EnumName.class);
soapObj.addAttribute(attrInfo);

You can use it like this:

public enum EnumName {
    One(1),Two(2),Three(3);

    public final int value;

    MyEnum(final int value) {
        this.value = value;
    }
}

To get values would be:

EnumName e = EnumName.One;
int value = e.value; //= 1
String name = e.name(); // = "One"

To have the on attributes:

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);

There is also a similar question and to solve it was done this way please take a look also;

How to pass an enum value to wcf webservice

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM