ASP. NET Web Service Standard SOAP Development case code (custom authentication Security header SoapHeader)

Source: Internet
Author: User
Tags soap

Using System.Xml;
Using System.Xml.Serialization;
Using System.Web.Services.Protocols;
Using System.Configuration;
Using Service.Common.Constant;

Namespace Service.Common.Core.Head.Safe
{
<summary>
For security, the custom SOAP header
</summary>
[XmlRoot ("Security", Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public class Security:soapheader
{
Token _usernametokern = new token ();

Public Token UsernameToken
{
get {return _usernametokern;}
set {_usernametokern = value;}
}

<summary>
Pass in the correct user name and password, and compare it with the username and password stored in the message header.
</summary>
<param name= "Rightusername" ></param>
<param name= "Rightpassword" ></param>
<returns></returns>
public bool IsAuthorized (string rightusername, String Rightpassword)
{
return this. Usernametoken.username = = Rightusername &&
This. UsernameToken.Password.Value = = Rightpassword;
}

<summary>
Public constructs SOAP Header method
</summary>
<returns></returns>
public static Security Constructsafehead (string username, string passwordvalue, String passwordtype)
{
Security SoapHeader = new security ();
SoapHeader. UsernameToken = new Token ();
SoapHeader. Usernametoken.username = Username;
SoapHeader. Usernametoken.password = new Password ();
SoapHeader. UsernameToken.Password.Value = Passwordvalue;
SoapHeader. UsernameToken.Password.Type = Passwordtype;

return soapheader;
}
}
}

Using System;
Using System.Data;
Using System.Web;
Using System.Collections;
Using System.Web.Services;
Using System.Web.Services.Protocols;
Using System.ComponentModel;
Using Service.ESB.BaseData.Operation;
Using Service.Common.Core.ESB.Request;
Using Service.Common.Core.Head.Safe;
Using Service.Common.Core.ESB.Response;
Using Service.Common.Core.Base;
Using Service.ESB.BaseData.Simulation;
Using Service.Common.Log;
Using Service.Common.Core.Head.Test;
Using System.Xml;
Using System.Xml.Serialization;
Using Service.common;
Using Service.Common.Core.ESB.Base;
Using Service.Common.Constant;
Using Service.ESB.BaseData.Simulation.Operation;

Namespace Service.ESB.BaseData
{
<summary>
Classes that simulate common services for ESB bus data
</summary>
[WebService (Namespace = "Http://www.iec.ch/TC57/2008/schema/message")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[ToolboxItem (False)]
[XmlRoot (Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Simulativedatacommonservice
{
#region Private Fields
<summary>
Safety Head
</summary>
Private Security _safesoapheader;

<summary>
Test the identity header
</summary>
Private Testcasehead _testcaseheader;
#endregion

Properties that are exposed #region
[XmlElement (Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
Public Security Safesoapheader
{
get {return _safesoapheader;}
set {_safesoapheader = value;}
}

Public Testcasehead Testcaseheader
{
get {return _testcaseheader;}
set {_testcaseheader = value;}
}
#endregion

#region Service Methods
[SoapHeader ("Safesoapheader")]//safety head
[SoapHeader ("Testcaseheader")]//Test Header--for test-time labeling
[SoapDocumentMethod (Requestelementname = "Requestmessage", Responseelementname = "Responsemessage")]
[WebMethod (Description = "Interface for analog Data universal service")]
[Return:xmlelement ("Requestmessage"), XmlElement ("Header", typeof (Headerclass)), XmlElement ("Reply", typeof ( Replyclass)]
[XmlInclude (typeof (Requestmessage)), XmlInclude (typeof (Responsemessage))]
Public object[] Invokedataservice (Headerclass reqmsgheader, Requestclass reqmsgrequest)
{

}

}

ASP. NET Web Service Standard SOAP Development case code (custom authentication Security header SoapHeader)

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.