0
votes

Im trying to get my mvc3 app to call a web service over https. Here is my code:

 var basicHttpsBinding = new BasicHttpsBinding();
            basicHttpsBinding.MaxBufferPoolSize = 104857600;
            basicHttpsBinding.MaxBufferSize = 104857600;
            basicHttpsBinding.MaxReceivedMessageSize = 104857600;
            basicHttpsBinding.Security.Mode = System.ServiceModel.BasicHttpsSecurityMode.Transport;
            basicHttpsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

            var endpointAddress = new EndpointAddress("web service url.asmx");

            var cfClient = new ChannelFactory<ws_name_webreqSoap>(basicHttpsBinding, endpointAddress);


            ClientCredentials cc = cfClient.Endpoint.Behaviors.Find<ClientCredentials>();
            cc.ClientCertificate.SetCertificate(
                StoreLocation.LocalMachine,
                StoreName.My,
                X509FindType.FindByThumbprint,
                "00000000000000000000000000000000000"
                );

            cfClient.CreateChannel();

            var webServices = new ws_merit_webreqSoapClient(basicHttpsBinding, endpointAddress);

When i use "LocalMachine, i get the following error":

The client certificate is not provided. Specify a client certificate in ClientCredentials.

and when i use "currentUser" i get the following error:

Cannot find the X.509 certificate using the following search criteria: StoreName 'TrustedPeople', StoreLocation 'CurrentUser', FindType 'FindByThumbprint', FindValue

How can i fix the first error? What am i doing wrong?

Thanks

1
Are you passing the "00000000000000000000000000000000000" string to the SetCertificate method, or have you simply removed your thumbprint string from your code for pasting here?Justin Russo
ive just removed it for pasting hereNotaras
Is it throwing the error on this line... 'cfClient.CreateChannel();'?Justin Russo

1 Answers

1
votes

In your code, I don't see where you are adding the ClientCredentials instance as a behavior on your factory endpoint.

After creating the ClientCredentials instance and setting its properties... do this,

  cfClient.Endpoint.Behaviors.Add(cc); 

before calling, cfClient.CreateChannel();