How to pass an enum value to wcf webservice

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.


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.


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...

链接地址: http://www.djcxy.com/p/52248.html

上一篇: Parallel.Foreach中的Ninject异常

下一篇: 如何将枚举值传递给wcf webservice