c# - How to return my complex types from a wcf service, not model itself? -
i have separate layer complex types dataaccesslayer
(dal), separate layer business businesslogiclayer
(bl). create wcf service application project servicelayer
(sl) , added service use bl methods , dal complex type return value.
now,i have 1 problem in add refrence myservice in mvc project , :
when added refrence of myservice, in refrence.cs generate complex type each mycomplex type used it.
i want not generate complex type , use of complex type @ dal.
dal
using system.runtime.serialization; namespace dal { [datacontract] public partial class mycomplextype { //... [datamember] //my prop //... } }
bl
namespace bl { public partial class myrepository { public list<dal.mycomplextype> mymethod(int param1,int param2) { var parameters= new list<sqlparameter>(); parameters.add(new sqlparameter("param1",sqldbtype.int){ value = param1 }); parameters.add(new sqlparameter("param2",sqldbtype.int){ value = param2 }); var result = dal.runprocedure("myproc", parameters); return result.converttolist<dal.mycomplextype>(); } } }
sl
namespace sl { [servicecontract] public interface imyservice { [operationcontract] list<dal.mycomplextype> myservicemethod(int param1,int param2); } } namespace sl { public class myservice : imyservice { public list<dal.mycomplextype> myservicemethod(int param1, int param2) { bl.myrepository bl = new bl.myrepository(); list<dal.mycomplextype> result = bl.mymethod(param1, param2); return result; } } }
refrence.cs class in mymvcproject after added myservice refrence service :
//------------------------------------------------------------------------------ // <auto-generated> // code generated tool. // runtime version:4.0.30319.34014 // // changes file may cause incorrect behavior , lost if // code regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace mymvcproject.myservice { using system.data; [system.codedom.compiler.generatedcodeattribute("system.servicemodel", "4.0.0.0")] [system.servicemodel.servicecontractattribute(configurationname = "myservice.imyservice")] public interface imyservice { [system.servicemodel.operationcontractattribute(action = "http://tempuri.org/imyservice/myservicemethod", replyaction = "http://tempuri.org/imyservice/myservicemethodresponse")] [system.servicemodel.xmlserializerformatattribute(supportfaults=true)] mymvcproject.myservice.myservicemethodresponse myservicemethod(mymvcproject.myservice.myservicemethodrequest request); // codegen: generating message contract since operation has multiple return values. [system.servicemodel.operationcontractattribute(action="http://tempuri.org/imyservice/myservicemethod", replyaction="http://tempuri.org/imyservice/myservicemethodresponse")] system.threading.tasks.task<mymvcproject.myservice.myservicemethodresponse> myservicemethodasync(mymvcproject.myservice.myservicemethodrequest request); } /// <remarks/> [system.codedom.compiler.generatedcodeattribute("system.xml", "4.0.30319.33440")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(namespace="http://schemas.datacontract.org/2004/07/dal")] public partial class mycomplextype : object { //private props ... //.. /// <remarks/> //public props } //.... other bloks }
return type of used service refrence mthod mymvcproject.myservice.mycomplextype
mymvcproject.myservice.myserviceclient service = new mymvcproject.myservice.myserviceclient(); mymvcproject.myservice.mycomplextype result = service.myservicemethod(10,12);
insted of :
dal.mycomplextype result = service.myservicemethod(10,12);
how resolved it? problem?
edited
my vs version 2013.
i test method in wpf
project , result ok,that means service not create self complex type , use dal complex type.
but in mvc
project both cheked , unchecked reuse types in refrenced assemblies
in service configuration service create self complex types.
i not know how resolve problem or reason ?
i think doesn't works that, specially when adding service reference. remember doesn't reference actual dll in client once adding service reference.
upon serializing datacontract re-create own classes serializer can recognize , matter adding namespaces , upon deserializing in service check namespace identity equivalent object/class in actual object in service:
[system.xml.serialization.xmltypeattribute(namespace="http://schemas.datacontract.org/2004/07/dal")] public partial class mycomplextype : object { . . . }
if want use own dal in client why don't create client proxy or channelfactory programmatically , physically add dal.
take @ links on how create proxy programmatically:
Comments
Post a Comment