How to pass an enum value to wcf webservice
Asked Answered
A

2

7

can ksoap2 pass an enum to webservice?

there is a wcf webservice:

[OperationContract]
string TestEnum(CodeType code);

CodeType is dotnet enum:

    public enum CodeType
    {
        [EnumMember]
        ALL,

        [EnumMember]
        VehicleColor
    }

How can i call this wcf webservice at android client?

i create a enum CodeType and implements KvmSerializable. In method getPropertyInfo, what is the value of info.name(info.type)?

public enum CodeType implements KvmSerializable, BaseInterface {
    ALL,

    VehicleColor;
//.......
    @Override
    public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) {
        //info.namespace = this.NameSpace;
        info.name = ?;
        info.type = ?;

    }
}

Thanks for your help.

Astri answered 29/4, 2011 at 3:48 Comment(2)
I have the same issue, did anyone resolve this? Thanks in advance!Leucomaine
@cbuck12000: Not sure if you'll get notified of my answer or not, thought I'd make sure you knew...Fourchette
H
4

I just solved that enum-Problem via Marshal.

I created a Java-Enum "copying" the .net one. I then wrote a Marshal-Class for it:

public class MarshalEnum implements org.ksoap2.serialization.Marshal
{
    ... // Singleton-Pattern

     public Object readInstance(XmlPullParser xpp, String string, String string1,
                           PropertyInfo pi)
        throws IOException, XmlPullParserException
{
    return MyEnum.valueOf( xpp.nextText() );
}

public void writeInstance(XmlSerializer xs, Object o)
        throws IOException
{
    xs.text(((MyEnum)o).name());
}

public void register(SoapSerializationEnvelope sse)
{
    sse.addMapping(sse.xsd, "MyEnum", MyEnum.class, MarshalEnum.getInstance() );
}
} // class

Then, when calling the Method where MyEnum-Values shall be sent:

//... blah blah
SoapSerializationEnvelope envelope =
                          new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.addMapping(SOAP_REMOTE_NAMESPACE, "MyEnum", MyEnum.class,       
                    MarshalEnum.getInstance());
//... and so on.

Note that SOAP_REMOTE_NAMESPACE is the data contract namespace of the enum to be used! See the wsdl-file to find it out if you're not sure. Should look something like "http://schemas.datacontract.org/2009/08/Your.dotNet.Namespace".

I hope this is going to work for you, too.

Havener answered 29/11, 2011 at 12:5 Comment(0)
F
0

Have you got

[ServiceContract]
[ServiceKnownType(typeof(CodeType))]
public interface ITheService
{
    [OperationContract]
    string TestEnum(CodeType code);
}

and

[DataContract]
public enum CodeType 
{
    // ...
}

?

Edit:

A bit of searching also turned up this, which may be of use...

Fourchette answered 6/6, 2011 at 13:54 Comment(1)
I think my issue is with KSoap2. How to send an enum value parameter to a web service method or handle an enum property within a class that is returned by a method). I can serialize complex objects and such, but no enums??Leucomaine

© 2022 - 2024 — McMap. All rights reserved.