How to pass enum value to wcf webservice

can ksoap2 pass the listing to the webservice?

there is wcf webservice:

[OperationContract] string TestEnum(CodeType code); 

CodeType is a dotnet enumeration:

  public enum CodeType { [EnumMember] ALL, [EnumMember] VehicleColor } 

How can I call this wcf web service on android client?

I am creating a CodeType enumeration and implements KvmSerializable. In the getPropertyInfo method, 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 = ?; } } 

Thank you for your help.

+7
source share
2 answers

I just solved this problem of listing through a marshal.

I created the Java-Enum by copying .net. Then I wrote a marshal class for him:

 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 ​​will 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 for the enumeration to be used! See the wsdl file to find out if you are not sure. It should look something like this: "http://schemas.datacontract.org/2009/08/Your.dotNet.Namespace".

I hope this works for you too.

+4
source

You have

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

and

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

?

Edit:

I searched a little and turned out to be this one , which may be useful ...

0
source

All Articles