Preface:
When the client fails to carry non-anonymous authentication modes such as Basic Authentication/digest authentication in IIS, the client must provide the corresponding credential.
Important Notes:
1. How to generate proxy class
When using the WSDL command, you must provide the user name and password connected to the Web service to generate proxy. The syntax is as follows:
WSDL http: // WebService-Uri/WebService. asmx/Username: yourusername/password: yourpassword
2. How to submit client credential and certificate in the client application.
In order to submit the credential of the client, we must create a credential of the client, and then submit it to the server together with the proxy instance for verification, as shown below:
Service1 proxy = new service1 ();
System. net. networkcredential credential = new system. net. networkcredential ("yourusername", "yourpassword", "yourdomain ");
Proxy. Credentials = credential;
Then we need to specify the client's Certificate (public-key part), as follows:
System. Security. cryptography. x509certificates. x509certificate Cert = new system. Security. cryptography. x509certificates. x509certificate ("yourcertificate-publickey.cer ");
Proxy. clientcertificates. Add (CERT );
In this way, the client provides credential and certificate and submits them together to the server. :) of course, everything above is done, the precondition is that the Web Service server is configured in the basic/digest authencation + certificate mode.