For example, in the previous section, the following sections are different:
1. Reset the security mode bound in Section 1 as follows:
<! -- Add the following bindings configuration node to start --> <bindings> <wshttpbinding> <binding name = "mybehaviorconfiguration"> <security mode = "transport"> <transport clientcredentialtype = "Basic "/> <! -- Here, the verification is empty and changed to basic --> </Security> </binding> </wshttpbinding> </bindings> <! -- Add the following bindings configuration node to end -->
2. Update Service reference (update the client configuration file app. config)
Actually, only one place is changed:
By <transport clientcredentialtype = "NONE"
Change <transport clientcredentialtype = "Basic"
3. Add the verification code to the client:
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. net; // using system. net. security; // using system. security. cryptography. x509certificates; // Add the X509 Certificate namespace wcfclient {class program {static void main (string [] ARGs) {try {wcfserver. service1client wcfclient = new wcfclient. wcfserver. service1client (); string strreturn = "Se Nd to Server String !! "; // Here the authentication is performed (Add the following two sentences based on the previous lesson) wcfclient. clientcredentials. username. username = "Administrator"; wcfclient. clientcredentials. username. password = "AA"; // this step is critical. It overwrites the server's verification method, that is, do not verify, directly send the request to the server // rewrite the method for verifying the server certificate. System. net. servicepointmanager. servercertificatevalidationcallback + = mycertificatevalidate; strreturn = wcfclient. getdata (strreturn); console. write (strreturn); console. read ();} catch (exception e) {console. writeline ("exception: {0}", E. message);} console. writeline ("press any key to exit"); console. read ();} Private Static bool mycertificatevalidate (Object sender, x509certificate cert, x509ch Ain chain, sslpolicyerrors error) {// trust any certificate !!! System. Console. writeline ("Warning, trust any certificate"); Return true ;}}}
So far, the Windows Authentication WCF has been completed.