<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Calling Remote ASP.NET Web Services from JQuery</title>
	<atom:link href="http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/</link>
	<description></description>
	<lastBuildDate>Mon, 15 Mar 2010 17:35:57 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: runxc1</title>
		<link>http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/comment-page-1/#comment-42920</link>
		<dc:creator>runxc1</dc:creator>
		<pubDate>Thu, 15 Jan 2009 20:15:55 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/#comment-42920</guid>
		<description>Let me start off by saying that I know that asp.net can be fairly picky about how you send and recieve JSON especially with dates.   What you have done looks decent but you should realy give jmsajax  a look it is a plugin for jQuery made for asp.net.   Below is a little snippet that works wonderfully

 $.jmsajax({
              url: &quot;Default.aspx&quot;,
              method: &quot;SomeMethod&quot;,
              data: {containerIdsAssigned: containerIdsAssigned, containerIdsUnAssigned: containerIdsUnAssigned},   
              success: function(jsonResponse) {
                  //Do Something here
              }
        });</description>
		<content:encoded><![CDATA[<p>Let me start off by saying that I know that asp.net can be fairly picky about how you send and recieve JSON especially with dates.   What you have done looks decent but you should realy give jmsajax  a look it is a plugin for jQuery made for asp.net.   Below is a little snippet that works wonderfully</p>
<p> $.jmsajax({<br />
              url: &#8220;Default.aspx&#8221;,<br />
              method: &#8220;SomeMethod&#8221;,<br />
              data: {containerIdsAssigned: containerIdsAssigned, containerIdsUnAssigned: containerIdsUnAssigned},<br />
              success: function(jsonResponse) {<br />
                  //Do Something here<br />
              }<br />
        });</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Grundy</title>
		<link>http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/comment-page-1/#comment-42827</link>
		<dc:creator>Jason Grundy</dc:creator>
		<pubDate>Tue, 13 Jan 2009 22:35:10 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/#comment-42827</guid>
		<description>Here you go Maciej:

using System;
using System.Web;

namespace ABF.Reporting.Web
{
	public class JsonHttpModule : IHttpModule
	{
		private const string JSON_CONTENT_TYPE = &quot;application/json; charset=utf-8&quot;;
		
		#region IHttpModule Members
		public void Dispose()
		{
		}

		public void Init(HttpApplication app)
		{
			app.BeginRequest  = OnBeginRequest;
			app.ReleaseRequestState  = OnReleaseRequestState;
		}
		#endregion

		public void OnBeginRequest(object sender, EventArgs e)
		{
			HttpApplication app = (HttpApplication)sender;
			HttpRequest resquest = app.Request;
			if (!resquest.Url.AbsolutePath.Contains(&quot;ReportQueueService.asmx&quot;)) return;
			
			if (string.IsNullOrEmpty(app.Context.Request.ContentType))
			{
				app.Context.Request.ContentType = JSON_CONTENT_TYPE;
			}
		}

		public void OnReleaseRequestState(object sender, EventArgs e)
		{
			HttpApplication app = (HttpApplication)sender;
			HttpResponse response = app.Response;
			if (app.Context.Request.ContentType != JSON_CONTENT_TYPE) return;

			response.Filter = new JsonResponseFilter(response.Filter);
		}
	}
}

using System.IO;
using System.Text;
using System.Web;

namespace ABF.Reporting.Web
{
	public class JsonResponseFilter : Stream
	{
		private readonly Stream _responseStream;
		private long _position;

		public JsonResponseFilter(Stream responseStream)
		{
			_responseStream = responseStream;
		}

		public override bool CanRead { get { return true; } }

		public override bool CanSeek { get { return true; } }

		public override bool CanWrite { get { return true; } }

		public override long Length { get { return 0; } }

		public override long Position { get { return _position; } set { _position = value; } }

		public override void Write(byte[] buffer, int offset, int count)
		{
			string strBuffer = Encoding.UTF8.GetString(buffer, offset, count);
			strBuffer = AppendJsonpCallback(strBuffer, HttpContext.Current.Request);
			byte[] data = Encoding.UTF8.GetBytes(strBuffer);
			_responseStream.Write(data, 0, data.Length);
		}

		private string AppendJsonpCallback(string strBuffer, HttpRequest request)
		{
			return request.Params[&quot;callback&quot;]   &quot;(&quot;   strBuffer   &quot;);&quot;;
		}

		public override void Close()
		{
			_responseStream.Close();
		}

		public override void Flush()
		{
			_responseStream.Flush();
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			return _responseStream.Seek(offset, origin);
		}

		public override void SetLength(long length)
		{
			_responseStream.SetLength(length);
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			return _responseStream.Read(buffer, offset, count);
		}
	}
}</description>
		<content:encoded><![CDATA[<p>Here you go Maciej:</p>
<p>using System;<br />
using System.Web;</p>
<p>namespace ABF.Reporting.Web<br />
{<br />
	public class JsonHttpModule : IHttpModule<br />
	{<br />
		private const string JSON_CONTENT_TYPE = &#8220;application/json; charset=utf-8&#8243;;</p>
<p>		#region IHttpModule Members<br />
		public void Dispose()<br />
		{<br />
		}</p>
<p>		public void Init(HttpApplication app)<br />
		{<br />
			app.BeginRequest  = OnBeginRequest;<br />
			app.ReleaseRequestState  = OnReleaseRequestState;<br />
		}<br />
		#endregion</p>
<p>		public void OnBeginRequest(object sender, EventArgs e)<br />
		{<br />
			HttpApplication app = (HttpApplication)sender;<br />
			HttpRequest resquest = app.Request;<br />
			if (!resquest.Url.AbsolutePath.Contains(&#8221;ReportQueueService.asmx&#8221;)) return;</p>
<p>			if (string.IsNullOrEmpty(app.Context.Request.ContentType))<br />
			{<br />
				app.Context.Request.ContentType = JSON_CONTENT_TYPE;<br />
			}<br />
		}</p>
<p>		public void OnReleaseRequestState(object sender, EventArgs e)<br />
		{<br />
			HttpApplication app = (HttpApplication)sender;<br />
			HttpResponse response = app.Response;<br />
			if (app.Context.Request.ContentType != JSON_CONTENT_TYPE) return;</p>
<p>			response.Filter = new JsonResponseFilter(response.Filter);<br />
		}<br />
	}<br />
}</p>
<p>using System.IO;<br />
using System.Text;<br />
using System.Web;</p>
<p>namespace ABF.Reporting.Web<br />
{<br />
	public class JsonResponseFilter : Stream<br />
	{<br />
		private readonly Stream _responseStream;<br />
		private long _position;</p>
<p>		public JsonResponseFilter(Stream responseStream)<br />
		{<br />
			_responseStream = responseStream;<br />
		}</p>
<p>		public override bool CanRead { get { return true; } }</p>
<p>		public override bool CanSeek { get { return true; } }</p>
<p>		public override bool CanWrite { get { return true; } }</p>
<p>		public override long Length { get { return 0; } }</p>
<p>		public override long Position { get { return _position; } set { _position = value; } }</p>
<p>		public override void Write(byte[] buffer, int offset, int count)<br />
		{<br />
			string strBuffer = Encoding.UTF8.GetString(buffer, offset, count);<br />
			strBuffer = AppendJsonpCallback(strBuffer, HttpContext.Current.Request);<br />
			byte[] data = Encoding.UTF8.GetBytes(strBuffer);<br />
			_responseStream.Write(data, 0, data.Length);<br />
		}</p>
<p>		private string AppendJsonpCallback(string strBuffer, HttpRequest request)<br />
		{<br />
			return request.Params["callback"]   &#8220;(&#8221;   strBuffer   &#8220;);&#8221;;<br />
		}</p>
<p>		public override void Close()<br />
		{<br />
			_responseStream.Close();<br />
		}</p>
<p>		public override void Flush()<br />
		{<br />
			_responseStream.Flush();<br />
		}</p>
<p>		public override long Seek(long offset, SeekOrigin origin)<br />
		{<br />
			return _responseStream.Seek(offset, origin);<br />
		}</p>
<p>		public override void SetLength(long length)<br />
		{<br />
			_responseStream.SetLength(length);<br />
		}</p>
<p>		public override int Read(byte[] buffer, int offset, int count)<br />
		{<br />
			return _responseStream.Read(buffer, offset, count);<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maciej Nejmantowicz</title>
		<link>http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/comment-page-1/#comment-42821</link>
		<dc:creator>Maciej Nejmantowicz</dc:creator>
		<pubDate>Tue, 13 Jan 2009 18:19:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/#comment-42821</guid>
		<description>Jason,

Get post. Can you please share the code for the HttpModule?

Maciej</description>
		<content:encoded><![CDATA[<p>Jason,</p>
<p>Get post. Can you please share the code for the HttpModule?</p>
<p>Maciej</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sundeep</title>
		<link>http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/comment-page-1/#comment-39717</link>
		<dc:creator>Sundeep</dc:creator>
		<pubDate>Mon, 15 Dec 2008 12:49:05 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/#comment-39717</guid>
		<description>Hi,

By seeing this article I am wondering about the security issues by exposing the url in HTML source. If anyone can query web services hosted on other websites, then how can it be tackled.

Thanks,
Sundeep.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>By seeing this article I am wondering about the security issues by exposing the url in HTML source. If anyone can query web services hosted on other websites, then how can it be tackled.</p>
<p>Thanks,<br />
Sundeep.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexei</title>
		<link>http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/comment-page-1/#comment-39014</link>
		<dc:creator>Alexei</dc:creator>
		<pubDate>Sun, 07 Dec 2008 20:00:05 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/#comment-39014</guid>
		<description>Best article about. NET   jsonp   jQuery. Thank you.</description>
		<content:encoded><![CDATA[<p>Best article about. NET   jsonp   jQuery. Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop - December 3, 2008 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/comment-page-1/#comment-38679</link>
		<dc:creator>Dew Drop - December 3, 2008 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Wed, 03 Dec 2008 14:33:52 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/#comment-38679</guid>
		<description>[...] Calling Remote ASP.NET Web Services from jQuery (Jason) [...]</description>
		<content:encoded><![CDATA[<p>[...] Calling Remote ASP.NET Web Services from jQuery (Jason) [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
