serialization - WCF Polymorphism in service contract -
i trying create service operation accepts, parameter, object implements specific interface. have thought easy accomplish, running problems (what guessing serialization problems not certain). have following contract:
//unsustainable because need method each of (currently) //3 student types, plus have 2 more root categories have multiple subtypes public interface iemailtemplateaccess { [faultcontract(typeof(validationfault))] [faultcontract(typeof(errorresponse))] [operationcontract] [transactionflow(transactionflowoption.allowed)] templateresponse getstudenttemplate(itemplaterequest request); }
and like:
public interface iemailtemplateaccess { [faultcontract(typeof(validationfault))] [faultcontract(typeof(errorresponse))] [operationcontract] [transactionflow(transactionflowoption.allowed)] templateresponse gettemplate(itemplaterequest request); }
in service use abstract factory return correct template based on type of request comes in. in addition, have created concrete itemplaterequests different kinds of templates returned. example, have template request types , b. template request type can have 1 of 3 sub types, subtype1, subtype2 , subtype3. created subtype3 request implemented itemplaterequest interface (subtype3request).
i hate have create method each request type have (i.e. getsubtype1template, getsubtype2template, getsubtype3template, gettypebtemplate, etc) become unwieldy types of templates can changing occasionally.
is there way have contract method accept implements itemplaterequest parameter , let factory work of figuring out type of template get?
so far, have following methods in service:
//not part of contract right although public iemailtemplate gettemplate(itemplaterequest request) { templatefactorybuilder builder = new templatefactorybuilder(); itemplatefactory factory = builder.gettemplatefactory(request.type); var template = factory.gettemplate(request); return template; } //contract method --this parent request type (requesttypea) above. //there 3 subtypes of student type public templateresponse getstudenttemplate(studentemailtemplaterequest request) { var response = new templateresponse { requiresprocessing = true }; response.template = (emailmergetemplate) gettemplate(request); return response; }
sorry link-ish answer, it's pretty long.. you're after (i think) here: http://blogs.msdn.com/b/morgan/archive/2009/08/05/polymorphism-in-wcf.aspx
it boils down using known types. this;
[servicecontract] [serviceknowntype("getknowntypes", typeof(commandservicehelper))] public interface icommandservice
Comments
Post a Comment