如何将枚举值传递给 wcf webservice

发布于 2024-11-04 00:49:45 字数 776 浏览 4 评论 0原文

ksoap2 可以将枚举传递给 web 服务吗?

有一个WCF Web服务:

[OperationContract]
string TestEnum(CodeType code);

CodeType是dotnet枚举:

    public enum CodeType
    {
        [EnumMember]
        ALL,

        [EnumMember]
        VehicleColor
    }

我如何在Android客户端调用这个WCF Web服务?

我创建了一个枚举 CodeType 并实现了 KvmSerializable。在方法 getPropertyInfo 中,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 = ?;

    }
}

感谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

土豪 2024-11-11 00:49:45

我刚刚通过 Marshal 解决了这个枚举问题。

我创建了一个“复制”.net 的 Java-Enum。然后,我为其编写了一个 Marshal-Class:

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-Values 的方法时:

//... 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”。

我希望这对你也有用。

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.

用心笑 2024-11-11 00:49:45

你有

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

和吗

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

编辑:

一些搜索也出现了这个,这可能有用...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文