Practical examples for establishing Web service security in .NET

Daily Newsletters

Sign up to ZDNet UK's daily newsletter.

The method then performs the authentication you need by verifying the user ID and password variables contained within the secureCtx object. If the LoginUser() method determines that the user is valid, it generates an authentication ticket that's inserted into the response's cookies collection. The HelloWorld() method is an example of a method you would call on the Web service once your client is authenticated. This pattern requires less coding because you need to authenticate only once in a given session and wrap your Web service implementation logic with a simple check, like so:
  • If Context.User.Identity.IsAuthenticated = True Then...
Client implementation
Once you've implemented the Web service and it's ready to go, you're ready to code the Web service consumer. The one drawback to this pattern is that the client must have cookies enabled to maintain the security ticket. Typically, the client would be a Web browser, which obviously provides built-in cookie handling, assuming the user has not disabled it. But what if you want your Web service accessible by a desktop Windows application? Consuming Web services from a desktop application provides an incredible amount of power, flexibility, and extensibility. The sample code in Listing B shows how to consume your Web service from a Windows application. To implement your Web service correctly, you must import System.Net.CookieContainer. This allows you to create an instance of a CookieContainer object, named cookieContainer1, which will store the authentication ticket returned by our LoginUser() method in the Web service. Private WSObjAs New
Next, you need to create an instance of your Web service itself:
  • SecureWebServiceTesterProxy.SecureWebServiceTester().
This must be declared globally at the form level because your authentication ticket must maintain state across the various methods implemented on your Windows Form. Within the New() method, which is generated by VS.NET, you set your Web service object's CookieContainer property to your cookieContainer1 object. This tells the Web service object to use your own cookie container object to store any cookies returned by your Web service. To consume your Web service from another ASP.NET application, you would use nearly identical code with the exception of the manual cookie storage code. Are you secure?The code samples in Listings A and B are simple demonstrations of how to programmatically secure your Web services by denying access to any client who does not have a validated authentication ticket. The level of security model complexity should be dictated by your business requirements. If your data sensitivity is high, you should take measures to ensure that your customer data is as secure and private as possible.

Talkback

Why do I click on the Listing A hyperlink to only be taken to a page that is not listing A and has nothing to do with this article?

via Facebook 20 April, 2004 17:10
Reply

Hi,

Good day to you.

I am impressed after reviewing your web site and company services.

Here I would like to propose a "mission-critical" solution to boost your sales, marketing and customer service via your web site. We have a solution known as BOTizen | www.botizen.com that could complement your business to achieve great result.

We have a very interesting proposition to propose that could add value to your company’s services.

Can you please direct me to the appropriate person in charge so that I can get in touch with him/her immediately? I would appreciate if you could send me his/her name and e-mail address for contact.

Thank you very much.

via Facebook 29 June, 2004 05:44
Reply

Great!
But I can't found source code

via Facebook 21 August, 2004 17:38
Reply

For everybody who cannot open the Listings use this Link to view the Article

http://builder.com.com/5100-6389-5034851.html#Listing%20A

via Facebook 10 February, 2005 15:16
Reply

This is a great article but it seems that the code samples links are broken (Listing A and B) which is not too good. Do you have those available somewhere or updated links that you could send me?

via Facebook 17 July, 2006 12:26
Reply

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

Freebies202

Duplicate comments are not made intentionally. Its very good to know that now you are keeping check on this problem because sometimes a commenter...

5 hours ago by Freebies202 on Microsoft fixes blog comments, speeds up blogs with open source
kevinmchapman

"the very significant number of users" and "many (most) of us" - you have no evidence for these statements. It is a fact that most users are saying...

13 hours ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
Marg Menzies Harrison

Another grammar faux pas is the improper use of "you". When sitting down down in a restaurant, for example, I get cringe when the waitress...

14 hours ago by Marg Menzies Harrison via Facebook on 10 flagrant grammar mistakes that make you look stupid
zdnetukuser

And NOW, folks, for Canonical's next trick... Kubuntu is late. Here's a pencil. Draw your own conclusions. cf.:...

15 hours ago by zdnetukuser on Linux Minterface
Moley

@kevinmchapman. The discussion here reflects the very significant number of users who really do like the traditional menu system and who wish to...

17 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

Er, no... It is an efficient means of finding the application/file/setting you need in one place. The icons are a simply a fallback for when you...

18 hours ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

Isn't the provision of a text based search an admission by the developers that the mass of icons approach does not work? I don't need to use a...

20 hours ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

"Unity and GNOME 3 both abandon the old text-based cascading menus in favour of a graphical icon-driven system." Point truly missed. Both use a...

20 hours ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

whs001 - Thank you, I'm glad you liked the article. I absolutely agree with you on your first point. I should perhaps have made it clearer that...

20 hours ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
Dennis Nilsson

If we allow corporate interest to dictate the way our government circumvents due process against foreign entities then we should accept the same...

21 hours ago by Dennis Nilsson via Facebook on ACTA stumbles in Germany
GHar123

I totally dislike pirating of works, I fear that artists will be deterred from creating works if they think that they are going to get ripped off....

23 hours ago by GHar123 on ACTA stumbles in Germany
JCB33

How dare film makers, artists or anybody that invests in creativity stop us pirating their works for free. I want to be able to walk into my local...

1 day ago by JCB33 on ACTA stumbles in Germany
Moley

@GrueMaster. I prefer horses for courses rather than one size fits all. I, and I suspect most other computer users, do not really wish to have...

1 day ago by Moley on A tale of two distros: Ubuntu and Linux Mint
greycynic

The product that scares me every time I have to use it is the Office 2007 version of Excel. The first bug that I found was applying the median...

1 day ago by greycynic on Ten flawed products that derail productivity
GrueMaster

Nice review and very informative. One thing I'd like to add (in reply to whs001's 1st question), the main reason to have the same interface from...

1 day ago by GrueMaster on A tale of two distros: Ubuntu and Linux Mint
Frederick Wrigley

I'be been using Mint 12 since the RC came out, and I am far more happy with the Cinnamon, the Mate, and, yes (with extensions), theGnome 3...

1 day ago by Frederick Wrigley via Facebook on A tale of two distros: Ubuntu and Linux Mint
bdantas

Excellent article. One small correction, though--although a fresh installation of Linux Mint 12 will, indeed, provide the user with a version of...

1 day ago by bdantas on A tale of two distros: Ubuntu and Linux Mint
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

1 day ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

1 day ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Moley

For Gnome 2 die-hards, it is possible to add icons to the bottom panel (or top top panel, if you prefer) which provide the exact Gnome 2...

1 day ago by Moley on A tale of two distros: Ubuntu and Linux Mint