September 8, 2010  
  You are here:  Home
Module Border Module Border
My Book

 

Module Border Module Border

QTCommunicationSimplified50.gif


Try Radicomm's Quicktalk, the first enterprise-class Push-To-Talk application for your Motorola/Symbol rugged devices, in your distribution center for free.

Click here to enter the 21st Century.


test
 Main Sections
   
test
 My Other Sites
   
Module Border Module Border
Friend's Books

Pro WF/.NET 3.5


Pro WF/.NET 3.0





 

Module Border Module Border
test
 Top Referrals
   
test
 Feedback
 





Cancel   Send
 
test
 Site Map
   

This site has been visited 86407 times.

  Add NetSplore to my favorites.

    Turning Ideas Into Reality  

 

thinker.jpg

Turning your ideas into reality is not just a catchy phrase, it's what we do. It has become expected that legitimate companies have a web presence. But more than likely, website development is not your expertise. What is a company to do?

Let NetSplore create the first impression your potential customers see.  With your ideas and our web savvy, we can create a website that will make a lasting impression on your customers, or prospective customers.

You can have a sales presence 24 hours a day. A support presence 24 hours a day.  You can have sales leads waiting for you when your staff arrives in the morning. Not cold leads, but interested potential customers that took enough interest to find you!

       

Interested in Language Integrated Query (LINQ)?
 

If you are interested in learning about Microsoft's Language Integrated Query (LINQ) for the .NET platform, please visit our other site http://www.linqdev.com.

 

 
.NET 3.5 Books Now Available
 

Pro LINQ: Language Integrated Query in C# 2008


Click here to purchase.

by Joe Rattz

Visit LINQDev.com

Pro WF: Windows Workflow in .NET 3.5


Click here to purchase.

by Bruce Bukovics

Visit LearnWorkflow.com

 
.NET 3.0 Books Available
 

Pro WF: Windows Workflow in .NET 3.0


Click here to purchase.

by Bruce Bukovics

Pro WPF: Windows Presentation Foundation in .NET 3.0


Click here to purchase.

by Matthew MacDonald

Pro WCF: Practical Microsoft SOA Implementation


Click here to purchase.

by Amit Bahree, Shawn Cicoria, Dennis Mulder, Nishith Pathak, Chris Peiris

 
Module Border Module Border
Random Tips Random Tips

CTRL+ENTER == Auto www and com for domain
In Internet Explorer, if you want to go to a site that is www.somesitename.com, you can just enter somesitename and press CTRL+ENTER and IE will change the url to www.somesitename.com. For example, enter netsplore and press CTRL+ENTER, and IE will change it to www.netsplore.com. Obviously, the domain has to be a .com domain for this to work.

Module Border Module Border
Tip Of The Week
 
Free IE Web Development Toolbar
This useful utility plugs into your browser and provides all sorts of useful things. Just to list a few, onscreen rulers and magnifier, html element outliner, html element tree view, styles, etc. Don't leave home without this one from Microsoft.
Free Microsoft Development Environments - Visual Studio 2008 Beta 2
Microsoft's Express editions of Visual Studio 2008 Beta 2 are free and available here.
Free .NET Controls!!!
Some free WinForm and WebForm controls courtesy of Developer Express. Get them while you can.
Site With Nice Images
This subscription site has some very nice graphic images. While there is a fee for the subscription, thumbnail sized images are free.
Really Cool FREE WinForm Controls
This page has a list of some really awesome free WinForm controls.
MSDN Chats
This is your chance to ask the Microsoft technololgy gurus your questions.
Good Stock Photo Site
Need some professional looking images for that Powerpoint presentation? Try the creatingonline.com site out,
How To Send Text Messages To Cell Numbers
This is a good resource for determining how to send a text message to a cell phone.
JSI Inc.
This is a good site for Windows registry hacks.
Pinoy VII
This site is full of great Paint Shop Pro tutorials. If you use Paint Shop Pro, do youself the favor of checking out these links.
Sysinternals.com
This site has many great free utilities for developers.
Free ContainerGuy DotNetNuke Container
A free DotNetNuke container for ContainerGuy.com registered users.
Free Icons
Literally hundreds of great looking icons for free. Nothing makes a site look better than great looking images.
Free PDF Converter
This totally free application installs as a virtual printer and allows you to create PDF files from virtually any application such as MS Word, MS Excel, etc. There are no restrictions, no watermarks, no spyware, no adware, and no pop-up advertisements. Thank you EXP Systems.
Free DotNetNuke Containers
Free courtesy Nina Meiers. You must login to download them though.
Microsoft Webcasts
There seems to always be a webcast going on here.
 
Consuming a RESTful Web Service Using HTTP POST from .NET
 
Location: BlogsNetSplore's Blog    
Posted by: Joe Rattz 8/21/2009 10:02:58 AM

Consuming a RESTful Web Service Using HTTP POST from .NET

I recently had the need to consume a RESTful web service with .NET.  What made this less typical than most articles I found on the internet is that instead of retrieving data with the web service via an HTTP GET, I needed to send data with the web service via an HTTP POST.  I didn't see anyone doing that.

So this blog post is here for three purposes.  First, it is here to help others needing to call any RESTful web service from .NET using an HTTP POST.  Second, it is here so that next time I need to do it, I can find it quickly.  Third, anyone else needing to consume the specific Taxcient web service that I was consuming may find this a helpful starting point.

The web service I needed to call is hosted by a company named Taxcient.  Their web service allows me to pass customer data to it using an HTTP POST.  Here is the basic code I used:

using System.Net;

//  The following List contains each record I am passing to the web service.
List records = GetData();

//  Create a single string containing all the records.
StringBuilder data = new StringBuilder();
foreach (string record in records)
{
    data.AppendLine(record);
}

WebClient request = new WebClient();

//  Add the required headers.
request.Headers.Add("Authorization", 
                    string.Format("Basic {0}", GetAuthenticationCredentials()));

request.Headers.Add("Content-Type",
                    TaxcientFileSettings.TaxcientInterfaceSettings.ContentType);

try
{
    string results = request.UploadString(url, "POST", data.ToString());

    using (StringReader reader = new StringReader(results))
    {
        string result;

        //  Read off the mode line.  This is Taxcient specific.
        result = reader.ReadLine();
        if (result != null)
        {
            //  Read off the header line.  This is Taxcient specific.
            result = reader.ReadLine();
            if (result != null)
            {
                while ((result = reader.ReadLine()) != null)
                {
                    //  Handle each result.  Check for errors, log, etc.
                }
            }
        }
    }
}
catch (Exception ex)
{
    //  Handle the exception.
}

I have removed all the error handling, logging, and data-specific logic.

First, I had a List containing each record I needed to pass to the web service.  Of course this is completely dependent on the actual web service you are calling.  The Taxcient service needed lines of comma-delimited text records.  Each item in my list was a comma-delimited line of text.

I found that using the WebClient class worked best for my needs.  I tried some other .NET classes such as WebRequest/HttpWebRequest but couldn't get them to work for my needs.  Since I needed to pass a string of data to the WebClient UploadString method, I needed to build a string of every line in my list.  So I created a StringBuilder and looped through each item in the list appending it to the StringBuilder.

Next I instantiated my WebClient object.  The Taxcient web service required me to pass the authorization credentials and content type as headers to the HTTP POST, so I added them next.

I then called the WebClient's UploadString method which is where the web service call happens.  I get back a string of results that I then read through using a StringReader.  The Taxcient web service actually returns two lines prior to the actual results, a mode line and a header line.  This is Taxcient specific and you probably won't have to do this.  After I read off the mode and header lines, I then loop through all the remaining lines.  Each of those lines is a success/error message corresponding to each record from my original list.

That's all it took.  Not much code at all really.  And, if I didn't have to read off the mode and header lines, and handle them separately, it would have been several lines shorter still.

Copyright ©2009 Joe Rattz
Permalink |  Trackback
 
Articles
 
Since posting my article titled "Calling AS/400 (AS400) RPG Programs From ASP.NET", I have gotten a good bit of feedback and questions. This is further evidence of how difficult it is to find good information about interfacing with the AS/400. Due to some of the questions and comments posted about that article, I thought I would do a little more research, and post a follow-up article.   Read More...
Now would probably be a good time to point out that when I first started creating articles for NetSplore, my intent was not only to share information with others, but to share it with myself...in the future! I can't tell you how many times I have had to go scrambling trying to figure out what code did something I needed to do again. So, I thought that if there was something I was having trouble remembering how to accomplish, others may have the same problem, and I should create an article.   Read More...
Have you ever needed to raise a button-click event programmatically? I sure have. Sometimes you end up needing to programmatically simulate that a button was clicked by a user, but how do you accomplish this? ...   Read More...
Have you ever had to wrestle with HTML or CSS rendering issues? Working in a compiled language environment like ASP.NET can be exasperating sometimes. The cycle time of edit, compile, and test can get very fristrating when you are making many small changes trying to determine why something is not rendering the way you would expect.   Read More...
Have you ever wondered how you might use C# multicast delegates in a real world scenario? Have you ever had two controls with interdependence and wanted a technique to decouple them?   Read More...
Have you ever needed to call an RPG program running on an AS/400 from ASP.NET? Here's how I do it.   Read More...
Have you ever wanted to reference an image in a forum post or blog, but had no place to host the image? Here's one.   Read More...
Have you ever needed a 3-state checkbox? Have you ever wanted to provide a gaphic instead of seeing the normal checkbox or radio button? I know I have.   Read More...
Have you ever had a button that caused serious problems if the user clicked it more than once? Here is some code to prevent that.   Read More...
Have you ever wondered what a shadow module is good for? Me too.   Read More...
Have you ever wanted a tooltip that didn't timeout and that you could control the look of the text? This free ASP.NET server control will do it.   Read More...
Have you ever needed a way to highlight ASP.NET DataGrid rows on the client side as the user moused over them? Here's how.   Read More...

 
New Features
 
Check here for the latest NetSplore features.

 
    






Favorite Sites
   
"Dare to be gorgeous and unique. But don't ever be cryptic or otherwise unfathomable. Make it unforgettably great."
    -- RJ Mical - Father of Amiga Computer GUI, Intuition
 
Home|Freebies|Blog|Services|Articles|ASP.NET Depot|DotNetNuke Central|Contact Us
  Copyright 2005 Netsplore Terms Of Use Privacy Statement