<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.southworks.net/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.southworks.net/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Edgardo Rossetto's Blog</title>
	
	<link>http://blogs.southworks.net/erossetto</link>
	<description>Just another Southworks weblog</description>
	<pubDate>Thu, 05 Jun 2008 18:44:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.southworks.net/erossetto" type="application/rss+xml" /><item>
		<title>Raw HTTP POST with WCF</title>
		<link>http://feeds.southworks.net/~r/erossetto/~3/318565145/</link>
		<comments>http://blogs.southworks.net/erossetto/2007/09/03/raw-http-post-with-wcf/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 17:40:18 +0000</pubDate>
		<dc:creator>erossetto</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/erossetto/2007/09/03/raw-http-post-with-wcf/</guid>
		<description><![CDATA[(From an interesting thread in the MSDN forums&#8230;)
WCF does not support raw HTTP requests with the content-type &#8216;application/x-www-form-urlencoded&#8217; (which is the content-type the browser sends when you hit &#8217;submit&#8217; in a &#60;form&#62; element) out of the box unless you treat the request body as a Stream.
This makes sense if you consider that the same principle [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.southworks.net/erossetto/files/2008/06/rawhttppostwcf.zip"></a>(From an interesting thread in the <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2009880&amp;SiteID=1">MSDN forums&#8230;</a>)</p>
<p>WCF does not support raw HTTP requests with the content-type <em>&#8216;application/x-www-form-urlencoded&#8217;</em> (which is the content-type the browser sends when you hit &#8217;submit&#8217; in a &lt;form&gt; element) out of the box unless you treat the request body as a <a href="http://msdn2.microsoft.com/en-us/library/system.io.stream.aspx">Stream</a>.</p>
<p>This makes sense if you consider that the same principle applies when returning data, as you can see <a href="http://www.cloudsamples.net/ContextBar/SrcViewer/?name=PictureServices&amp;f=PictureSyndication\PictureService.cs">here</a> in the Picture Services sample, both the GetDocumentation() and GetPicture() operations return a Stream with data; all you need to do is set the content-type properly and you&#8217;re good to go.</p>
<p>I&#8217;ve created a little sample that shows how to POST data from a HTML form and parse it in WCF with a little help from the System.Web namespace.</p>
<p>Consider the following service contract:</p>
<div class="code">
<div class="codePadder">
<div style="font-size: 10pt;color: black;font-family: consolas,courier new">
<pre style="margin: 0px">[<span style="color: #2b91af">ServiceContract</span>]</pre>
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: #2b91af">ISampleService</span></pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">    [<span style="color: #2b91af">OperationContract</span>]</pre>
<pre style="margin: 0px">    [<span style="color: #2b91af">WebInvoke</span>(UriTemplate = <span style="color: #a31515">"invoke"</span>)]</pre>
<pre style="margin: 0px">    <span style="color: blue">void</span> DoWork(<span style="color: #2b91af">Stream</span> input);</pre>
<pre style="margin: 0px">}</pre>
</div>
</div>
</div>
<p>Sample HTML form:</p>
<p><a href="http://blogs.southworks.net/erossetto/files/2008/06/ie-form.png"><img src="http://blogs.southworks.net/erossetto/files/2008/06/ie-form-thumb.png" border="0" alt="ie_form" width="413" height="275" /></a></p>
<p>HTML source:</p>
<div class="code">
<div class="codePadder">
<div style="font-size: 10pt;color: black;font-family: consolas,courier new">
<pre style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">form</span><span style="color: blue"> </span><span style="color: red">method</span><span style="color: blue">=</span>&#8220;<span style="color: blue">post</span>&#8220;<span style="color: blue"> </span><span style="color: red">action</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Service.svc/invoke</span>&#8220;<span style="color: blue">&gt;</span></pre>
<pre style="margin: 0px"><span style="color: blue">    &lt;</span><span style="color: #a31515">label</span><span style="color: blue"> </span><span style="color: red">for</span><span style="color: blue">=</span>&#8220;<span style="color: blue">firstName</span>&#8220;<span style="color: blue">&gt;</span>First Name<span style="color: blue">&lt;/</span><span style="color: #a31515">label</span><span style="color: blue">&gt;</span>: <span style="color: blue">&lt;</span><span style="color: #a31515">input</span><span style="color: blue"> </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">text</span>&#8220;<span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">firstName</span>&#8220;<span style="color: blue"> </span><span style="color: red">value</span><span style="color: blue">=</span>&#8220;&#8221;<span style="color: blue"> /&gt;</span></pre>
<pre style="margin: 0px"><span style="color: blue">    &lt;</span><span style="color: #a31515">br</span><span style="color: blue"> /&gt;&lt;</span><span style="color: #a31515">br</span><span style="color: blue"> /&gt;</span></pre>
<pre style="margin: 0px"><span style="color: blue">    &lt;</span><span style="color: #a31515">label</span><span style="color: blue"> </span><span style="color: red">for</span><span style="color: blue">=</span>&#8220;<span style="color: blue">lastName</span>&#8220;<span style="color: blue">&gt;</span>Last Name<span style="color: blue">&lt;/</span><span style="color: #a31515">label</span><span style="color: blue">&gt;</span>: <span style="color: blue">&lt;</span><span style="color: #a31515">input</span><span style="color: blue"> </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">text</span>&#8220;<span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">lastName</span>&#8220;<span style="color: blue"> </span><span style="color: red">value</span><span style="color: blue">=</span>&#8220;&#8221;<span style="color: blue"> /&gt;</span></pre>
<pre style="margin: 0px"><span style="color: blue">    &lt;</span><span style="color: #a31515">p</span><span style="color: blue">&gt;&lt;</span><span style="color: #a31515">input</span><span style="color: blue"> </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">submit</span>&#8220;<span style="color: blue"> /&gt;&lt;/</span><span style="color: #a31515">p</span><span style="color: blue">&gt;</span></pre>
<pre style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: #a31515">form</span><span style="color: blue">&gt;</span></pre>
</div>
</div>
</div>
<p>Here&#8217;s how you read the input Stream:</p>
<div class="code">
<div class="codePadder">
<div style="font-size: 10pt;color: black;font-family: consolas,courier new">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">void</span> DoWork(<span style="color: #2b91af">Stream</span> input)</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">    <span style="color: #2b91af">StreamReader</span> sr = <span style="color: blue">new</span> <span style="color: #2b91af">StreamReader</span>(input);</pre>
<pre style="margin: 0px">    <span style="color: blue">string</span> s = sr.ReadToEnd();</pre>
<pre style="margin: 0px">    sr.Dispose();</pre>
<pre style="margin: 0px">    <span style="color: #2b91af">NameValueCollection</span> qs = <span style="color: #2b91af">HttpUtility</span>.ParseQueryString(s);</pre>
<pre style="margin: 0px">    <span style="color: blue">string</span> firstName = qs[<span style="color: #a31515">"firstName"</span>];</pre>
<pre style="margin: 0px">    <span style="color: blue">string</span> lastName = qs[<span style="color: #a31515">"lastName"</span>];</pre>
<pre style="margin: 0px">    <span style="color: green">// Do work here</span></pre>
<pre style="margin: 0px">}</pre>
</div>
</div>
</div>
<p><a href="http://blogs.southworks.net/erossetto/files/2008/06/rawhttppostwcf.zip">I&#8217;ve attached the full sample</a>.</p>
<p>Hope this helps</p>
<img src="http://feeds.southworks.net/~r/erossetto/~4/318565145" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/erossetto/2007/09/03/raw-http-post-with-wcf/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=erossetto&amp;itemurl=http%3A%2F%2Fblogs.southworks.net%2Ferossetto%2F2007%2F09%2F03%2Fraw-http-post-with-wcf%2F</feedburner:awareness><feedburner:origLink>http://blogs.southworks.net/erossetto/2007/09/03/raw-http-post-with-wcf/</feedburner:origLink></item>
		<item>
		<title>Picture Services Sample Released</title>
		<link>http://feeds.southworks.net/~r/erossetto/~3/318565146/</link>
		<comments>http://blogs.southworks.net/erossetto/2007/08/30/picture-services-sample-released/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 18:55:28 +0000</pubDate>
		<dc:creator>erossetto</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[Orcas]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/erossetto/2007/08/30/picture-services-sample-released/</guid>
		<description><![CDATA[As Justin announced here, the Picture Services sample was released a few days ago. It&#8217;s cool when a project you&#8217;re involved in (in my case helping the DPE folks) sees the light.  
The sample centers around the new WCF 3.5 Syndication API, and shows a variety of cool technologies and scenarios (more info on [...]]]></description>
			<content:encoded><![CDATA[<p>As Justin announced <a href="http://blogs.msdn.com/justinjsmith/archive/2007/08/20/check-out-picture-services.aspx">here</a>, the Picture Services sample was released a few days ago. It&#8217;s cool when a project you&#8217;re involved in (in my case helping the DPE folks) sees the light. <img src='http://blogs.southworks.net/erossetto/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The sample centers around the new WCF 3.5 Syndication API, and shows a variety of cool technologies and scenarios (more info on the Picture Services <a href="http://www.cloudsamples.net/PictureServices/">homepage</a>), here&#8217;s a list of my favorite features shown in the sample that will hopefully catch your attention:</p>
<ol>
<li>How easy is to load and work with any feed on the web (ATOM or RSS) with the new Syndication API </li>
<li>How to extend feeds with custom extensions, the sample shows how to add <a href="http://blogs.msdn.com/rssteam/articles/SimpleListExtensionsExplained.aspx">SLE</a> (Simple List Extensions) to a RSS feed </li>
<li>How to add <a href="http://en.wikipedia.org/wiki/RSS_Enclosures">enclosures</a> </li>
<li>How to return HTML documents with WCF      </li>
</ol>
<p><a href="http://www.netfx3.com/files/folders/sampleservices/entry11931.aspx">Click here to download the bits</a></p>
<p>Other resources:</p>
<ol>
<li><a href="http://www.cloudsamples.net/ContextBar/SrcViewer/?name=PictureServices">Browse the source code online</a> </li>
<li><a href="http://www.cloudsamples.net/PictureServices/feed.svc/pictures">Browse the Picture Services feed here</a>       </li>
<li><a href="http://channel9.msdn.com/Showpost.aspx?postid=334896">&quot;A lap around Picture Services&quot;</a>, a screencast by <a href="http://blogs.msdn.com/justinjsmith/">Justin Smith</a>       </li>
</ol>
<img src="http://feeds.southworks.net/~r/erossetto/~4/318565146" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.southworks.net/erossetto/2007/08/30/picture-services-sample-released/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=erossetto&amp;itemurl=http%3A%2F%2Fblogs.southworks.net%2Ferossetto%2F2007%2F08%2F30%2Fpicture-services-sample-released%2F</feedburner:awareness><feedburner:origLink>http://blogs.southworks.net/erossetto/2007/08/30/picture-services-sample-released/</feedburner:origLink></item>
	<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetFeedData?uri=erossetto</feedburner:awareness></channel>
</rss>
