or years now, SSL has been the magic bullet for securing HTTP messaging. While you can use this encryption-based technology to secure SOAP messages over HTTP, it limits Web service functionality. SSL requires a negotiation between messaging endpoints to exchange keys and establish encryption, so messaging secured by SSL must be fully decrypted at each endpoint before the contents of a message can be read. In other words, when using SSL, your application must pay the processing cost of decrypting each message?even before it can read the SOAP message headers to determine, for example, that the message needs to be re-encrypted and forwarded to another application. Clearly, applications need a security solution that better enables such complex message routing. To fulfill that need, representatives from IBM, VeriSign, and Microsoft teamed up to draft the WS-Security specification.
Inside the WS-Security Specification
WS-Security introduces the concept of security tokens. These XML-based tokens contain claims about the sender of a SOAP message, and can include data sufficient to prove these claims. Username tokens, which will be the focus of this article, can contain a username and optionally a password or a cryptographically-derived password hash. Signed security tokens, such as X.509 or Kerberos-based tokens, are binary security tokens encoded as base-64 binary XML. They include cryptographic endorsements made by a token-issuing authority.
SOAP messages transport these security tokens in the new Security header element. Applications can use the header contents to authenticate the sender and secure the message itself. Rather than proposing a new set of security technologies, WS-Security leverages existing XML security specifications, including XML Encryption and XML Signature; cryptographic algorithms, such as SHA-1 and Triple-DES; and authentication mechanisms, such as X.509 and Kerberos.
|
Implementing WS-Security
To implement the WS-Security specification in your Web service or consuming client application, you must be able to write security elements to and read them from your SOAP messages, and you must have access to standard cryptographic algorithms. While it’s certainly possible to do the necessary XML serialization yourself, you can avoid extra work by leveraging out-of-the-box implementations of WS-Security offered by IBM, Microsoft and others. In this article, I will focus on Microsoft’s implementation of WS-Security in its Web services Enhancements (WSE) offering. In particular, you’ll see how to use the WSE 2.0 Technical Preview release to secure a request to the classic “Hello World” Web service.
Welcome to WSE 2.0
WSE is Microsoft’s solution for supporting advanced Web services functionalities, including security, reliable messaging, and policies. WSE, which supports both TCP and HTTP transports, implements a set of input and output filters as well as a rich API.
WSE input filters intercept incoming SOAP messages and translate supported SOAP header elements into programming objects, which are accessible using the SoapContext object. WSE output filters construct SOAP headers based on the properties of the SoapContext object for the outgoing message. The WSE runtime, which hosts these filters and API, is implemented in the .NET assembly Microsoft.Web.Services.dll.
WSE also supports Web service policies, which ensures that incoming messages have the required headers and can automate the securing of outbound messages.
To follow the code in the remainder of this article, you should download and install the WSE 2.0 Technical Preview before continuing.
| Author’s Note: WSE 2.0 integrates with Visual Studio 2003. To benefit from this integration, select the Visual Studio Tools option during installation; this installs all of the tools that I discuss in this article. |
You configure WSE 2.0 on a per-application basis by adding XML elements to the application configuration file. Modifying the configuration lets you change the default behavior of WSE without recompiling your application, but it is tricky to edit these files without making mistakes. To avoid such errors, I recommend setting configuration parameters through the WSE Settings Tool, a Visual Studio add-in for WSE 2.0 installed when you select the Visual Studio Tools option during installation.
Configuring a WSE-based Application
After installing Visual Studio 2003 and WSE 2.0, you can create and build the sample code for this article. For a simple introduction, you’ll create a client application to access a “Hello World” Web service. After completing this simple test case, you’ll be able to use the same techniques to access any WS-Security-enabled Web service.
Creating the Hello World service is trivial. Create a new Web service project, and uncomment the HelloWorld Web method, and compile the project. You will follow the same steps to enable WSE for the service as you do for the client. Now, you can create a client application to consume the service.
- After creating a new client application in Visual Studio 2003 (you can use any project type), right-click the project in the “Solution Explorer” pane and select “WSE Settings 2.0?.” This displays the WSE Settings Tool shown in Figure 1.
![]() |
Adding a Security Token Because all messages sent to a WSE-enabled application must contain at least one security token, you need to instruct WSE to add a username token to the application’s request to the Hello World Web service. You do that by adding a UsernameToken object to the SoapContext for the request message. The following code adds a UsernameToken and a new digital signature to the SoapContext object before making the Web service request to the GetHelloWorld method.
Note that by using a signature as proof-of-possession, you can specify the PasswordOption.SendNone so WSE doesn’t send the password in the header. In this case, WSE generates a UsernameToken element in the message’s Security header. The following code shows the WS-Security header from a digitally signed message. When WSE digitally signs a message, it uses the supplied security token to generate the signature. WSE generated this Security header using the UsernameToken object shown in the preceding listing.
When instantiating a UsernameToken object, you have the option of specifying how WSE handles the password, which you must always supply. Never hard-code passwords into your application. When WSE adds a UsernameToken element to the message, it creates a Username element as well as Nonce and Created elements. These elements hold data used to prevent replay attacks and to stiffen a hashed password against dictionary attacks when using the PasswordOption.SendHashed option. However, because even a hashed password is vulnerable to a brute force dictionary attack, a better solution, aside from encrypting the transport, is to use the PasswordOption.SendNone option. Authenticating Security Tokens To securely use username tokens for authentication, you need to implement your own usernametoken manager, in a class that derives from UsernameTokenManager, and register it with WSE. This works particularly well for a custom authentication scheme; you simply retrieve the password that corresponds to the username and return it to WSE, which automatically compares it to the value of the password or password hash in the UsernameToken element. Even if you do not send a password, WSE can use your retrieved password to validate an attached digital signature, thereby verifying authentication. I don’t have the space to fully cover security token managers here, but I do show how to do this in my book. You can also see this example on MSDN. Adding Digital Signatures Encrypting Messages To sum up, WS-Security provides a solid framework for securing SOAP messaging. However, other specifications like WS-Trust, WS-SecureConversation, WS-SecurityPolicy, and WS-Federation have been proposed to build even more robust and functional security scenarios. Out of the box, WSE provides an immediate security benefit by blocking all request messages that cannot be authenticated and that contain invalid digital signatures or encryption. With a little effort, you can configure WSE to provide much needed security for .NET Web services. While this article focused on username tokens, other solutions, like X.509, provide a higher level of security and functionality. Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience. Related PostsAbout Our Editorial ProcessAt DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere. See our full editorial policy. ![]() What Is GitHub Copilot Computer Use? GitHub’s New Desktop Agent Explained
Rashan Dixon
October 23, 2026
8:08 AM
![]() The SaaS Release Bottleneck: Why Faster Development Doesn’t Always Mean Faster Delivery
Rashan Dixon
October 22, 2026
3:41 PM
![]() Choosing an Online Graduate Program: Accreditation, Flexibility, Support and What You Should Know.Â
John Rampton
October 22, 2026
3:08 PM
![]() What Is SlugFest, the npm Trusted Publishing Vulnerability?
Deanna Ritchie
October 22, 2026
1:00 PM
![]() What Is VS Code Agent Sandboxing? Microsoft’s New AI Agent Security Layer Explained
Steve Gickling
October 21, 2026
12:44 PM
![]() Meta Muse Wonder: Pricing, Benchmarks, and What It Means for Developers
Rashan Dixon
October 20, 2026
7:56 AM
![]() What Are GitHub Actions Workflow Lockfiles?
Deanna Ritchie
October 19, 2026
9:52 AM
![]() What Is Grok Voice 3.0? xAI’s New Speech-to-Speech Model Explained
Steve Gickling
October 16, 2026
10:27 AM
Google’s Gemini Argon Wins Through Reach, Not Revolution
Joe Rothwell
October 15, 2026
10:50 AM
![]() What Is the GhostApproval Vulnerability in AI Coding Assistants?
Johannah Lopez
October 15, 2026
8:09 AM
![]() Startup Challenges DoorDash With $1 Delivery Fee
Steve Gickling
October 14, 2026
4:01 PM
![]() AI Insiders Urge New York Oversight
Sumit Kumar
October 14, 2026
3:03 PM
![]() Pro-AI Political Group Builds Bipartisan War Chest
Steve Gickling
October 14, 2026
1:36 PM
![]() Prysm Capital Leader Links Parenting to Investing
Sumit Kumar
October 14, 2026
11:43 AM
![]() McDonald’s Faces Antitrust Suit Over AI Pricing
Rashan Dixon
October 14, 2026
11:11 AM
![]() OpenAI Addresses Australian Health Site Hack Probe
Rashan Dixon
October 14, 2026
11:04 AM
![]() Industry Leaders Sign White House AI Accord
Kirstie Sands
October 14, 2026
10:37 AM
![]() What Is the AgentCorruption Vulnerability in AWS AgentCore?
Priya Nandakumar
October 14, 2026
7:39 AM
![]() Lincoln Lab Tracks AI Hardware Since 2018
Rashan Dixon
October 13, 2026
2:54 PM
![]() Divided Court Rejects AI Lab’s Rights Claims
Rashan Dixon
October 13, 2026
11:29 AM
![]() Countries Eye Drones to Boost Rainfall
Steve Gickling
October 13, 2026
11:09 AM
![]() UK Watchdog Investigates Recruitment Robo Calls
Kirstie Sands
October 13, 2026
10:14 AM
![]() Nexstrom Raises Funds for 2D Chip Equipment
Sumit Kumar
October 13, 2026
9:36 AM
![]() Atlassian Deepens OpenAI Ties, Retains AI Choice
Deanna Ritchie
October 13, 2026
9:17 AM
AI’s Real Race Is Utility, Not Intelligence
Joe Rothwell
October 13, 2026
8:12 AM
|























