asp.net the steps in the page to invoke SoapHeader for verification: practical Tips

Source: Internet
Author: User
Tags soap

This article is for you to share the ASP.net page to invoke the SOAP header for validation of the Web services operation steps for your reference, the details are as follows

The first step: the class used for soap validation must derive from the SoapHeader class, and the public properties in the class will appear in the auto-generated XML node, that is:

<soap:Header>
  <usersoapheader xmlns= "http://tempuri.org/" >
   <username>string</ username>
   <Pwd>string</Pwd>
  </UserSoapHeader>
</soap:Header>

Public Class Usersoapheader:soapheader
{
  private string _username;
  private string _pwd;
 
  The properties of public will automatically generate the XML node public
  string UserName
  {get {return
    _username;}
    set {_username = value;}
  }
 
  public string Pwd
  {get
    {return _pwd;}
    set {_pwd = value;}
  }
}

Step Two:
in the WebServices service class, add a public property (must be public), type from Usersoapheader

///<summary>///WebService Summary description///</summary> [WebService (Namespace = "http://tempuri.org/")] [webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)] public class WebService:
 
  System.Web.Services.WebService {//This property will be the name in the Soapheaderattribute of the Validation property/method Consistent with this variable public usersoapheader userheader;
  Public WebService () {//If you are using a design component, uncomment the following line//initializecomponent ();
  [WebMethod] [SoapHeader ("Userheader")]//here is important, the name to be consistent with the defined validation property name!  When the public string HelloWorld () {//is entered into this method, Userheader will automatically have a value of if (Userheader!= null) {return "' is RetVal
    : "+ userheader.username;
  Return ' check not successed '; }
}

Step three: Call on the client:
1. Add Web References
2. Instantiation Service class
3. Instantiating the SOAP header (a property that is automatically generated for validation at the client; usersoapheader; the name of the property is: Usersoapheadervalue); The Auto-generated property generation rule is: Validate type name +value;
4. Invoke the method provided by the service.

WebService s = new WebService ();
    Usersoapheader a = new Usersoapheader ();
    A.username = "admin";
    A.PWD = "ZZ";
    S.usersoapheadervalue = A; This property is automatically generated
    Response.Write (S.helloworld ());//This is Retval:admin
 

Very simple, I hope everyone can grasp the asp.net in the SoapHeader for verification steps, thank you for your reading.

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.