![]() |
Fox's Pages | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
UW home
|
Updated: January 23, 2006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This may help you get a Microsoft.net(C#) client to work with a C&C webservice that requires a UWCA client certificate.
C&C webservices require UWCA certificates for both server and client authentication.
In your Visual Studio 2005 project (we'll call it "WSApplication"):
This will be likely added with the name of the wsdl's ip name. Change that now to something more useful, e.g. "EDSServices".
In your c# program:
using WSApplication.EDSServices; using Microsoft.Web.Services2.Security.X509; using System.Security.Cryptography.X509Certificates;
WSE 3.0
using WSApplication.EDSService; using Microsoft.Web.Services3.Security.X509; using System.Security.Cryptography.X509Certificates;
/* Retrieve a certificate by subject name from the Local Machine store. */
private X509Certificate GetCert(string subject)
{
X509Certificate cert = null;
X509CertificateStore store =
X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
store.OpenRead();
X509CertificateCollection col =
store.FindCertificateBySubjectString(subject);
try {
cert = col[0];
} catch (Exception e) {
throw new Exception("Cert not found");
}
return (cert);
}
WSE 3.0
/* Retrieve a certificate by subject name from the Local Machine store. */
private X509Certificate GetCert(string subject)
{
X509Certificate cert = null;
X509Store store = new X509Store(StoreName.My,
StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col =
store.Certificates.Find(X509FindType.FindBySubjectName,
subject, true);
try {
cert = col[0];
} catch (Exception e) {
throw new Exception("Cert not found");
}
return (cert);
}
Suppose for this example that the wsdl defined a service named "EDSService" that exported a "gettypes" binding. You might call it using:
X509Certificate cert = GetCert("your_cert_name");
EDSService eds = new EDSService();
eds.ClientCertificates.Add(cert);
string[] types = eds.gettypes(user_id);
|
Jim Fox UW Technology Identity and Access Management University of Washington fox@washington.edu |
© 1983-2012, University of Washington