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
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
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
// 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");
<%@ ServiceHost Language="C#" Debug="true" Service="MyServiceLibrary.MyServiceSample" %>
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Log.Info("Application_Start");
}
protected void Application_Error(object sender, EventArgs e)
{
var error = Server.GetLastError();
@vbilopav
vbilopav / s-7_3.xml
Last active September 2, 2015 14:09
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<!--
For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
public class WcfDynamicSoapProxy<T> : IDisposable where T : class
{
public static WcfDynamicSoapProxy<T> CreateProxy(string endpointAdressUri)
{
return new WcfDynamicSoapProxy<T>(endpointAdressUri);
}
protected readonly ChannelFactory<T> DynamicChannelFactory;
public T Channel { get; private set; }
using (var service = WcfDynamicSoapProxy<IMyServiceSample>.CreateProxy("http://localhost:53920/MyServiceSample.svc/soap"))
{
var response = service.Channel.DoSomeWork(new SomeWorkRequest(new { Param1=1, Param2="bla“}));
}
$.ajax({
url: "http://localhost:53920/MyServiceSample.svc/json/DoSomeWork?request=" +
JSON.stringify({ Param1: 1, Param2: "bla"})
contentType: "application/json",
dataType: "json",
type: "GET",
success: function(data) {
if (data.success) {
// do some stuff...
}
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<!-- JSONP Endpoints -->
<endpoint address="jsonp" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP"
behaviorConfiguration="jsonBehavior" contract="MyServiceLibrary.IMyServiceSample" />