web services - Is it possible to return interfaces from .net webservices or can one only return concrete classes? -


I built the need to return complex types from a web service and class MyComplexType applicable interface IMyComplexType Was there. Now in my web service I have a method to return that an object that is applied so as IMyComplexType:

  [WebMethod] public IMyComplexType GetMyComplexType () {IMyComplexType myCt = new MyComplexType (); ... myCt back; }  

Everything compiled fine but as this type it throws an exception when I run the web service:

  System.NotSupportedException: Interface MyWebService. IMyComplexType can not be done in sequence.  

Is this design or am I forgetting something, can I allow my classroom or interface to be decorated in some way? I have to finish all interfaces and provides solid and probably is to be able to do this work with .net webservices with base sections

Edit:

The interface I Trying to serialize:

  Public interface ICustomer {long Id {get; Set;} string name {get; Set;} string email address {receive; Set;}}  

No short answer, you will not return through an interface Can a WebServices

The long answer is that you can get the type of behavior you want, but this is a little bit of a kick. The solution is to use binary Dharawahikkrn you can serial byte of its kind, Web method is to return a series of bytes and the other side will turn back the bytes in your complex types.

For example

  [WebMethod] public byte [] GetMyComplexType () {IMyComplexType myCt = new MyComplexType (); ... MemoryStream Stream = New MemoryStream (); IFormatter fmt = New BinaryFormatter (); Fmt.Serialize (stream, myCt); Stream.Flush (); Byte [] bytes = stream Tore (); Stream.Close (); Return bytes; }  

You will need to convert everything back to the other side.

  byte [] bytes = service.GetMyComplexType (); Memory stream stream = new memorystream (bytes); BinaryFormatter fmt = new BinaryFomatter (); MyComplexType myCt = fmt.Deserialize (stream);  

You can clear deserialization by making a general method. I should add, you will need to make sure that you can reference complex types on the client.

Alternatively, if they are your interface then you can convert into intangible classes. However, this will not work if you want to apply multiple interfaces to class (or you are already successor to second class) because you can only get one class. If you need some polymorphic behavior on the client, then you have to use the XMLEngine attribute.


Comments