Example of WebService with soapheader Verification

Source: Internet
Author: User
The company asked me to write a user interface with another website, as shown below: Code

Using System;
Using System. collections;
Using System. componentmodel;
Using System. Data;
Using System. LINQ;
Using System. Web;
Using System. Web. Services;
Using System. Web. Services. Protocols;
Using System. xml. LINQ;

Namespace Userlogintest
{
///   <Summary>
/// Summary of checkuser
///   </Summary>
[WebService (namespace =   " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
[Toolboxitem ( False )]
// To allow ASP. Net ajax to call this web service from a script, uncomment the downstream service.
// [System. Web. Script. Services. scriptservice]
Public   Class Checkuser: system. Web. Services. WebService
{

///   <Summary>
/// Do not verify the Method
///   </Summary>
///   <Returns> </returns>
[Webmethod]
Public   String Helloworld ()
{
Return   " Hello World " ;
}

PublicMysoapheader soaphead= NewMysoapheader ();

///   <Summary>
/// Verification Method
///   </Summary>
///   <Param name = "userid"> </param>
///   <Param name = "username"> </param>
///   <Param name = "MSG"> </param>
///   <Returns> </returns>
[Soapheader ( " Soaphead " )]
[Webmethod]
Public   Bool Getuserinfo ( Int Userid, String Username, Out   String MSG)
{

String Deusername = Encrypthelper. decrypt (username, " Jjjyzy " );
MSG =   String . Empty;
If ( ! Soaphead. isvalid ( Out MSG ))
{ Return   False ;}

Else
{
ReturnCheckcount (userid, deusername );

}

}

///   <Summary>
/// Query ID and account
///   </Summary>
Private   Bool Checkcount ( Int Userid, String Username)
{
String Sqlstr =   " Select Table where id = userid and username = Username " ;

Return True;
}

}

///   <Summary>
/// Soaphead verification method account password LY (override a class)
///   </Summary>
Public   Class Mysoapheader: system. Web. Services. Protocols. soapheader
{
Public   String Wsusername
{ Get ; Set ;}
Public   String Wspwd
{ Get ; Set ;}

PublicMysoapheader ()
{

}

Public   Bool Isvalid ( Out   String MSG)
{
Return Isvalid (wsusername, wspwd, Out MSG );
}
Private   Bool Isvalid ( String Wsusername, String Wspwd, Out   String MSG)
{ // , Out string msg
MSG =   String . Empty;
If (Wsusername =   " Ly "   & Wspwd =   " Ly " )
{Msg =   " You have the right to call " ; Return   True ;}

Else{Msg= "You are not authorized to call";Return False;}
}

}
}

 

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.