Skip to content

Instantly share code, notes, and snippets.

View vbilopav's full-sized avatar
🏠
Working from home

Vedran Bilopavlović vbilopav

🏠
Working from home
View GitHub Profile
@vbilopav
vbilopav / s-5_1.cs
Last active September 1, 2015 09:56
[ServiceContract]
public interface IMyServiceSample
{
[OperationContract] //soap xml
[WebGet(ResponseFormat = WebMessageFormat.Json)] //json
bool DoSomeWork(int param1, string param2);
// …
[DataContract]
public class Result
{
[DataMember]
public bool Success { get; set; }
}
[DataContract]
public class SomeWorkParams
{
[DataContract]
public class Response
{
[DataMember]
public bool Success { get; set; }
}
[DataContract]
public class Request
{
[DataContract]
public class Response
{
[DataMember]
public List<ResponseError> Errors { get; set; }
[DataMember]
public List<string> Warnings { get; set; }
[DataMember]
public class MyServiceSample : WcfBaseService, IMyServiceSample
{
public DoSomeWorkResponse DoSomeWork(SomeWorkRequest request)
{
return new DoSomeWorkResponse();
}
public DoSomeOtherWorkResponse DoSomeOtherWork(SomeOtherWorkRequest request)
{
return new DoSomeOtherWorkResponse();
@vbilopav
vbilopav / s-6_2.cs
Last active September 1, 2015 13:28
[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();
}
}
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)
public class WcfErrorHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
return false;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (error == null)
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public interface IMyRequestResponseFactory
{
TResponse ProcessRequest<TResponse>(Request request, Func<TResponse> handler)
where TResponse : Response, new();
}