Study Notes: WCF Security (2) basic identity authentication (Windows account password) (wshttpbinding)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.