You can secure Web service communications by integrating security
mechanisms into your client application.
Why and when to perform this task
These security mechanisms can include
user name token (user
name and password), or custom binary and XML-based security tokens.
Steps for this task
- Download and install the Web Services Enhancements (WSE) 2.0 SP3
for Microsoft® .NET. This is available from the Microsoft
Download Center.
- Modify the generated proxy client code as follows.
Change:
public class Export1_MyMicroflowHttpService : System.Web.Services.Protocols.SoapHttpClientProtocol {
To:
public class Export1_MyMicroflowHttpService : Microsoft.Web.Services2.WebServicesClientProtocol {
Note: These
modifications are lost if you regenerate the proxy client by running the WSDL.exe tool.
- Modify the client application code by adding the following lines
at the top of the file:
using System.Web.Services.Protocols;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Security.Tokens;
...
- Add code to implement the desired security mechanism. For
example, the following code adds user name and password protection:
string user = "U1";
string pwd = "password";
UsernameToken token =
new UsernameToken(user, pwd, PasswordOption.SendPlainText);
me._proxy.RequestSoapContext.Security.Tokens.Clear();
me._proxy.RequestSoapContext.Security.Tokens.Add(token);