This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // see more at: https://github.com/JeremySkinner/FluentValidation | |
| using FluentValidation; | |
| public class CustomerValidator: AbstractValidator<Customer> { | |
| public CustomerValidator() { | |
| RuleFor(customer => customer.Surname).NotEmpty(); | |
| RuleFor(customer => customer.Forename).NotEmpty().WithMessage("Please specify a first name"); | |
| RuleFor(customer => customer.Discount).NotEqual(0).When(customer => customer.HasDiscount); | |
| RuleFor(customer => customer.Address).Length(20, 250); | |
| RuleFor(customer => customer.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyServiceSample : IMyServiceSample | |
| { | |
| private readonly IMyRequestResponseFactory _factory; | |
| public MyServiceSample(IMyRequestResponseFactory factory) //dependency injection via constructor | |
| { | |
| _factory = factory; | |
| } | |
| public MyServiceSample() // WCF poziva default konstruktor, i koristimo default implementaciju |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyRequestResponseFactory : IMyRequestResponseFactory | |
| { | |
| public TResponse ProcessRequest<TResponse>(Request request, Func<TResponse> handler) | |
| where TResponse : Response, new() | |
| { | |
| try | |
| { | |
| // Validacija request poruke (ovisno o tipu) | |
| // Autentifikacija korisnika - podaci iz request poruke | |
| // Autorizacija korisnika - podaci iz request poruke |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IMyRequestResponseFactory | |
| { | |
| TResponse ProcessRequest<TResponse>(Request request, Func<TResponse> handler) | |
| where TResponse : Response, new(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class WcfErrorHandler : IErrorHandler | |
| { | |
| public bool HandleError(Exception error) | |
| { | |
| return false; | |
| } | |
| public void ProvideFault(Exception error, MessageVersion version, ref Message fault) | |
| { | |
| if (error == null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void LogRequest() | |
| { | |
| if (OperationContext.Current == null) return; | |
| string msg = String.Empty; | |
| if (Properties.ContainsKey(RemoteEndpointMessageProperty.Name)) | |
| { | |
| RemoteEndpointMessageProperty remote = | |
| Properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; | |
| if (remote != null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [WcfErrorHandler] // custom atribut koji imeplementira IErrorHandler, logiranje sistemskih WCF grešaka | |
| public abstract class WcfBaseService | |
| { | |
| protected WcfBaseService() | |
| { | |
| if (OperationContext.Current == null) return; // ako WCF ne postoji, izađi odmah | |
| WcfUtils.LogRequest(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyServiceSample : WcfBaseService, IMyServiceSample | |
| { | |
| public DoSomeWorkResponse DoSomeWork(SomeWorkRequest request) | |
| { | |
| return new DoSomeWorkResponse(); | |
| } | |
| public DoSomeOtherWorkResponse DoSomeOtherWork(SomeOtherWorkRequest request) | |
| { | |
| return new DoSomeOtherWorkResponse(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [DataContract] | |
| public class Response | |
| { | |
| [DataMember] | |
| public List<ResponseError> Errors { get; set; } | |
| [DataMember] | |
| public List<string> Warnings { get; set; } | |
| [DataMember] |