Reputation: 967
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Security;
using Microsoft.Web.Services2.Security.Tokens;
using Microsoft.Web.Services2.Security.X509;
public void ConfigureService(string username, string password, string certKey)
{
var service = new WebServicesClientProtocol();
service.Url = url;
service.RequestSoapContext.Security.Tokens.Add(new UsernameToken(username, password, PasswordOption.SendPlainText));
var store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
store.OpenRead();
var cert = store.FindCertificateBySubjectString(certKey)[0];
var clientToken = new X509SecurityToken(cert);
store.Close();
service.RequestSoapContext.Security.Tokens.Add(clientToken);
var signature = new MessageSignature(clientToken);
service.RequestSoapContext.Security.Elements.Add(signature);
}
This is just initialization of the WebServicesClientProtocol, rest is just calling endpoints.
This is the code that is used to communicate with a service. Can it be written in just WCF to not use WSE?
I tried
var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.TransportWithMessageCredential);
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
var address = new EndpointAddress(endpointAddress);
var client = new ServiceSoapClient(binding, address);
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindBySubjectName,
certName);
client.ClientCredentials.UserName.UserName = username
client.ClientCredentials.UserName.Password = password;
But it's not working, I just get
System.Web.Services.Protocols.SoapException: Access to the operation is not present.
at RecieversNamespace.Framework.ProcessMessage(SoapMessage message)
at System.Web.Services.Protocols.SoapMessage.RunExtensions(SoapExtension[] extensions, Boolean throwOnException)
at System.Web.Services.Protocols.SoapServerProtocol.CreateServerInstance()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
System.Web.Services.Protocols.SoapException: Access to the operation is not present.
When I add service endpoint, I'm not sure how to setup bindings to replicate the code above. Specifically the MessageSignature part.
Thanks
Upvotes: 1
Views: 157