Service which provides interface-impelementation instead of data -


since while i'm implementing services whenever possible servicestack (or webapi) instead of wcf.

what want sending interface (-name) server , class-implementation back. maybe that's confusing, i'll give example:

my service-client has multiple operations - "check form": logic checking form not implemented. has interface called iformchecker methods nameisvalid(string firstname, string middlename, string lastname).

instead of sending whole form-data server validation, client request implementation of iformchecker server.

i know that's possible wcf, have no idea how servicestack. if that's possible, what's way go? checked documentation, i'm not wiser.

it seams there's no "magic trick" or anything. have serialize/deserialize class "old-fashion way".

if you're interested, here's solution:

i created "root"-interface, in example imodule. imodule contains 1 property, called name. string , there convenience:

the iformchecker example derived interface: client knows value of name-property , of course interface itself. fire name-value server, return serialized class.

all have is:

var module = moduleimplementations.firstordefault(x => x.name == name); if(module == null) throw new someexception();  return module.serialize(); 

client-wise can deserialize , cast interface. that's it.

here's moduleserialization-class:

public static class moduleserialization {     public static string serialize(this imodule m)     {         using (var ms = new memorystream())         {             var bf = new binaryformatter();             bf.serialize(ms, m);              return convert.tobase64string(ms.toarray());         }     }      public static t deserialize<t>(string serialized) t : class, imodule     {         var ba = convert.frombase64string(serialized);          using (var s = new memorystream(ba))         {             var bf = new binaryformatter();             return bf.deserialize(s) t;         }     } } 

cheers!


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -