国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

WCF basicHttpBinding之Message Security Mode

2019-11-17 01:50:42
字體:
來源:轉載
供稿:網友

WCF basicHttpBinding之Message Security Mode

原創地址:http://www.survivalescaperooms.com/jfzhu/p/4067873.html

轉載請注明出處

前面的文章《WCF Security基本概念》介紹了WCF的security mode,簡單說Transport是transport級別上的加密,Message是message級別上的加密,參見下圖:

Transport Security

image

Message Security

image

(一)Demo代碼

IDemoService.cs:

using System.ServiceModel;namespace WCFDemo{        [ServiceContract(Name = "IDemoService")]    public interface IDemoService    {        [OperationContract]        [FaultContract(typeof(DivideByZeroFault))]         int Divide(int numerator, int denominator);    }}

DemoService.cs:

using System;using System.ServiceModel;using System.ServiceModel.Activation;namespace WCFDemo{    [aspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]    public class DemoService : IDemoService    {        public int Divide(int numerator, int denominator)        {            try            {                return numerator / denominator;            }            catch (DivideByZeroException ex)            {                DivideByZeroFault fault = new DivideByZeroFault();                fault.Error = ex.Message;                fault.Detail = "Denominator cannot be ZERO!";                throw new FaultException<DivideByZeroFault>(fault);            }                   }    }}

(二)創建證書

basicHttpBinding使用Message Security mode時,credential type只能為Certificate(參見《WCF Security基本概念》)

312317464879122

在服務器上創建服務器端證書。

image

屬性解析

-sr 指定的證書存儲區中的注冊表位置。

  • currentUser 指定注冊版存儲位置為 HKEY_CURRENT_USER.
  • localMachine 指定注冊版存儲位置為 HKEY_LOCAL_MACHINE.

-ss 指定證書存儲的位置。

-a 指定相關的算法,可以選擇 md5 算法或者 SHA1算法

-n 指定證書的名稱。該名稱遵循X.500命名標準。簡單例子如 "CN=MyName" 格式,如果沒有指定/n開關,證書默認的名稱是"Joe's Software Emporium"。

-sky 證書鍵類型。可以設置為 exchange 或者 signature。

-pe 證書可導出

-r Self-signed Certificate

證書創建成功,下面在證書控制單元查看證書的信息

image

image

選擇Certificates –> Add

image

image

image

image

image

需要給IIS運行WCF Service的application Pool的帳號對這個證書私鑰的讀權限(參考《IIS ApplicationPoolIdentity》)

image

否則會報出以下錯誤

image

將服務器端的證書導出,然后導入到客戶端。

從服務器導出證書:

image

image

image

image

image

image

image

將導出的證書復制到客戶端,然后導入:

image

image

QQ2euiwv5z0.png" alt="image" width="4

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灌阳县| 济南市| 汨罗市| 瑞丽市| 汉阴县| 东阿县| 崇州市| 山东省| 会宁县| 土默特右旗| 五莲县| 长宁区| 都匀市| 英超| 鄂伦春自治旗| 合肥市| 平原县| 荣成市| 禹城市| 海城市| 英德市| 高州市| 临沂市| 东丰县| 寻甸| 柳江县| 丹东市| 金昌市| 团风县| 渝中区| 永泰县| 千阳县| 化德县| 丰都县| 阿勒泰市| 蛟河市| 介休市| 灵台县| 利辛县| 托克托县| 钦州市|