I am trying to consume a web service that requires message signing for authentication. i have Created the Web service request object and populated it with data.
I have also Created a signature token using the X.509 certificate.
The final aim is to apply the token to web service request so that a digital signature is created for the BODY of the request and that signature should get appended to the request object.
below is the code i am using to generate token :
public SecurityManager(string serviceActor, bool isClient, string clientActor)
: base(serviceActor, isClient, clientActor)
{
}
public override void SecureMessage(SoapEnvelope envelope, Security security)
{
X509SecurityToken signatureToken = GetSecurityToken("subjectName");
if (signatureToken == null)
{
throw new SecurityFault("Message Requirements could not be satisfied.");
}
security.Tokens.Add(signatureToken);
MessageSignature sig = new MessageSignature(signatureToken);
security.Elements.Add(sig);
X509SecurityToken encryptionToken = GetSecurityToken("subjectName");
if (encryptionToken == null)
{
throw new SecurityFault("Message Requirements could not be satisfied.");
}
EncryptedData enc = new EncryptedData(encryptionToken);
security.Elements.Add(enc);
}
public X509SecurityToken GetSecurityToken(string subjectName)
{
X509SecurityToken objX509SecurityToken = null;
X509Store objX509Store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
objX509Store.Open(OpenFlags.ReadOnly);
try
{
X509Certificate2Collection objX509Certificate2Collection = objX509Store.Certificates.Find(X509FindType.FindBySubjectName, subjectName, true);
X509Certificate2 objX509Certificate2;
if (objX509Certificate2Collection.Count == 1)
{
objX509Certificate2 = objX509Certificate2Collection[0];
objX509SecurityToken = new X509SecurityToken(objX509Certificate2);
}
else
{
objX509SecurityToken = null;
}
}
catch (Exception ex)
{
objX509SecurityToken = null;
}
finally
{
if (objX509Store != null)
objX509Store.Close();
}
return objX509SecurityToken;
}
}
below is the code i am using to create web service request:
ServiceClient objServiceClient = new ServiceClient();
objServiceClient.send();
I want to know how can i apply security token to my web service request.