WCF - call method from service implementation -


what i'm trying following:

1) have following wcf service contract:

[servicecontract] public interface iuploadservice {     [operationcontract]     servicedata upload(request request); }  [datacontract] public class request {     [datamember]     public long abnnumber;      [datamember]     public string email; } 

2) contract implemented this.

public class uploadservice : iuploadservice {     public bool upload(request request)     {        // code     } } 

in "some code" section call validation class validate clients request, this:

var result = validation.validaterequest(request); 

so question is: bad idea create instance of validation class inside upload method? this:

public class uploadservice : iuploadservice {     public bool upload(request request)     {        var validation = new validation();         var result = validation.validaterequest(request);     } } 

i know can around creating constructor far know can't create constructor inside wcf service implementation class, or wrong?

i'm new wcf if i'm totally heading wrong direction please let me know.

thanks

personally little possible in service methods. have separate project handle upload. allows reuse code more easily, , test functionality without creating service.

as whether should create validation depends on does, make sure validation class implements interface containing validaterequest(request) , inject that. can mock in tests if need to.

so service code like

public class uploadservice : iuploadservice {     private readonly iuploadhandler _uploadhandler;      public uploadservice(iuploadhandler uploadhandler)     {         _uploadhandler = uploadhandler;     }      public bool upload(request request)     {        //would possibly mapping here create different type of object pass handler        _uploadhandler.upload(request);     } } 

and handler in different project like

public class uploadhandler : iuploadhandler {     private readonly ivalidation _validator;      public uploadhandler(ivalidation validator)     {         _validator = validator;     }      public bool upload(request request)     {         return _validator.validaterequest(request);     } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -