Denny.NET

I can haz ASP.NET goodness?

About the author

Denny Ferrassoli
Developer at Casting Networks. MCP / .NET
E-mail me Send mail
Add to Technorati Favorites

Recent posts

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Motivation: Michael Jordan

A friend of mine sent me a youtube video today and it struck a chord in me. No matter what our dreams are, or what we're going through in life we must always continue to work hard and pursue our dreams. Don't think that someone else got to where they are "just because." Sometime you're only looking at the surface

Stay motivated my friends!

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Blog
Posted by Denny on Saturday, September 20, 2008 9:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed

WCF REST and POST... Let's Dance!

I spent a good part of my day trying to get POST working with my WCF RESTful web service yesterday. Try as I might I just couldn't get my service to receive data via POST! So after a few hours of searching I finally came across the solution I needed. There isn't much information on setting all this up properly so I'm going to run through the configuration as well.

First get your configuration file ready, here's mine (By the way, I don't think the mex binding is necessary):

[code:xml]
 <system.serviceModel>
  <behaviors>
   <endpointBehaviors>
    <behavior name="FastBehavior">
     <webHttp/>
    </behavior>
   </endpointBehaviors>


   <serviceBehaviors>
    <behavior name="FastBehavior">
     <serviceMetadata httpGetEnabled="True" />
     <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
   </serviceBehaviors>
  </behaviors>


  <services>
   <service behaviorConfiguration="FastBehavior" name="Fast">
    <host>
     <baseAddresses>
      <add baseAddress="http://localhost:8080/ws/fast.svc" />
     </baseAddresses>
    </host>
    <endpoint address="" binding="webHttpBinding" contract="IFast" behaviorConfiguration="FastBehavior" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>
  </services>
 </system.serviceModel>
[/code]

Next throw a few attributes in your interface. First is the UriTemplate... I added a {user} parameter there but you don't have to pass any parameters through the uri if you don't want to. Second is the important part - the Method must be set to POST (in all caps). This tells WCF that the operation should only be accessible via POST, go ahead and try a GET to see for yourself.

Now here's the tricky part... Since I passed {user} as a param in the uri I can access it via "string user" but the POST data comes across as a Stream (The golden ticket!). This is the important part about sending data via POST! Check out the interface:

[code:c#]
[ServiceContract]
public interface IFast
{
 [OperationContract]
 [WebInvoke( UriTemplate="authorize/{user}", Method="POST" )]
 Fast.SampleReturnTypes Authorize( string user, Stream postInfo );
}
[/code]

But now I need to process the POST data... luckily it's pretty simple to parse the data.

As a matter of fact in this particular scenario I used a basic form to post the data, so my data comes across in querystring key value pairs like this: keyname=value1&keyname2=value2... and so on. So you can see it would be fairly easy to parse.

However the neat thing about this is that I don't have to use a form to post the data. I can post the data from an app or AJAX and instead of using querystring values I can send XML, JSON, Base64 encoded data, etc... You can pretty much send anything! In the implementation below I use the form submitted values and with our useful HttpUtility class I can easily parse my post data:

[code:c#]
 public SampleReturnTypes Authorize( string user, Stream postInfo )
 {
  using( StreamReader reader = new StreamReader( postInfo ) )
  {
   String resource = reader.ReadToEnd();
   System.Collections.Specialized.NameValueCollection coll = System.Web.HttpUtility.ParseQueryString( resource );
   
   // coll now contains your query string data
  }
  
  return new SampleReturnTypes();
 }
[/code]

That should get you started in the right track! I hope it helps you!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,
Categories: ASP.NET | Server-Side
Posted by Denny on Tuesday, September 16, 2008 11:20 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Concerned with Google's Chrome

Google Chrome

Google released Chrome, aka the Google Browser, and it has me a bit concerned. Why? Because I like it... As a developer and designer I hate to think that I may have yet another browser to code against. And thus it makes me concerned. Sure it's not a mainstream browser and it's a "research" project but deep down inside you and I can feel that this browser will be able to pull its weight. People will want to use it... People will use it. And so my developer side comes out and begs the question: What bugs lie beyond the younder Goog-o-browser? How will my web sites react, standards-compliant or not? On a personal level I ask myself: Do I want to let The Goog have first-class access to my browsing habits?

There are plenty of questions and plenty of concerns but one thing is for sure... Google is testing the waters. I'm curious to see what they will do in the future with Chrome. I trust the guys at Goog won't put developers through a hard time but I'm watching my back.

And while we're on the subject of browsers... "Save the Developers" - "Say NO to IE6"

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: Blog | General
Posted by Denny on Tuesday, September 02, 2008 8:35 PM
Permalink | Comments (0) | Post RSSRSS comment feed