新增Soap頭來增加Web Service的安全性

2021-06-07 12:15:27 字數 2660 閱讀 4042

專注於 .net (edobnet)

myservice.asmx.cs

新增類:

myheader

從system.web.services.protocols.soapheader繼承

完整的**如下

using

system;

using

system.collections;

using

system.componentmodel;

using

system.data;

using

system.diagnostics;

using

system.web;

using

system.web.services; //

對soap head引用新增的命名空間

using

system.web.services.protocols;

namespace

study

#region

元件設計器生成的**

//web

服務設計器所必需的

private icontainer components = null;

//////

設計器支援所需的方法-不要使用**編輯器修改

///此方法的內容。

///

private

void initializecomponent()

//////清理所有正在使用的資源。

///

protected

override

void dispose( bool disposing )

base.dispose(disposing);         }

#endregion

// web

服務示例

// helloworld()

示例服務返回字串hello world

// 若要生成,請取消注釋下列行,然後儲存並生成專案

// 若要測試此web服務,請按f5 鍵

[webmethod]

public

string helloworld()

[soapheader("myheader")]

[webmethod(description="ddddddd",enablesession=true)]

public

string helloworld2(string contents)

} public

class myheader : system.web.services.protocols.soapheader

//////

建構函式

///

///使用者id

///加密後的密碼

public myheader(string nuserid,string npassword)

#region屬性

//////

使用者名稱///

public

string userid

set }

//////

加密後的密碼

///

public

string password

set }

#endregion

#region方法

//////

初始化///

///使用者id

///加密後的密碼

public

void initial(string nuserid,string npassword)

//////

使用者名稱密碼是否正確

///

///使用者id

///加密後的密碼

///返回的錯誤資訊

///使用者名稱密碼是否正確

public

bool isvalid(string nuserid,string npassword,out

string nmsg)

else }

catch }

//////使用者名稱密碼是否正確

///

///使用者名稱密碼是否正確

public

bool isvalid(out

string nmsg)

#endregion }

} 通過soap

呼叫的**如下:

// 在此處放置使用者**以初始化頁面

//建立myservice物件

mywebserver.myservice service = new study.mywebserver.myservice(); //

建立soap頭物件

mywebserver.myheader header = new study.mywebserver.myheader(); //

設定soap頭變數

header.password = "admin";

header.userid = "admin";

service.myheadervalue = header; //

呼叫web方法

this.label1.text = service.helloworld2("dob");

單鏈表的增加 無頭結點

單鏈表的增加 無頭結點 本文展示單鏈表的增加 1.從頭部新增 2.從尾部新增 初始化單鏈表 typedef struct listnode listnode typedef listnode list 頭結點為空的初始化 param head void initlist list head 單鏈表插...

單鏈表的增加 有頭結點

單鏈表的增加 有頭結點 1.從頭部新增 2.從尾部新增 初始化單鏈表 typedef struct listnode listnode typedef listnode list 初始化單鏈表,頭結點不為空 param head void initlistheadnonull list head 單...

osip庫的擴充套件 增加SDP頭域

osip庫提供sdp的支援,主要在目錄src osipparser2下的sdp accessor.c和sdp message.c檔案中 以及對應的標頭檔案 對sdp擴充套件頭域支援主要是在這幾個檔案中增加相應的介面 1.在sdp message.h的資料結構struct sdp message中增加...