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
/*
jQuery pub/sub plugin by Peter Higgins ([email protected])
Loosely based on Dojo publish/subscribe API, limited in scope. Rewritten blindly.
Original is (c) Dojo Foundation 2004-2010. Released under either AFL or new BSD, see:
http://dojofoundation.org/license for more information.
*/
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:53738");
if (HttpContext.Current.Request.HttpMethod != "OPTIONS") return;
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
$.ajax({
url: "http://localhost:53920/MyServiceSample.svc/jsonp/DoSomeWork?request=" +
JSON.stringify({ Param1: 1, Param2: "bla"}) +
"&callback=?",
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" />
$.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...
}
using (var service = WcfDynamicSoapProxy<IMyServiceSample>.CreateProxy("http://localhost:53920/MyServiceSample.svc/soap"))
{
var response = service.Channel.DoSomeWork(new SomeWorkRequest(new { Param1=1, Param2="bla“}));
}
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; }
@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 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();
<%@ ServiceHost Language="C#" Debug="true" Service="MyServiceLibrary.MyServiceSample" %>