如何通过一个枚举值WCF web服务WCF、web

2023-09-06 02:58:09 作者:此生不离不弃

可以ksoap2传递一个枚举web服务?

can ksoap2 pass an enum to webservice?

还有一个WCF Web服务:

there is a wcf webservice:

[OperationContract]
string TestEnum(CodeType code);

codeTYPE是DOTNET枚举:

CodeType is dotnet enum:

    public enum CodeType
    {
        [EnumMember]
        ALL,

        [EnumMember]
        VehicleColor
    }

我怎样才能把这个WCF web服务的Andr​​oid客户端?

How can i call this wcf webservice at android client?

我创建了一个枚举codeTYPE并实现KvmSerializable。在为getPropertyInfo方法,什么是info.name(info.type)的值?

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.

我创建了一个Java的枚举复制的.NET之一。然后,我写了一个元帅级吧:

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

然后,调用的方法,其中MyEnum-值应送交时:

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.

注意的SOAP_REMOTE_NAMESPACE是要使用的枚举的数据合同的命名空间!看到WSDL文件找出来,如果​​你不知道。 应该是这个样子http://schemas.datacontract.org/2009/08/Your.dotNet.Namespace。

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.