原创地址:http://www.cnblogs.com/jfzhu/p/4071342.html

转载请注明出处

如何在WCF中使用Transport Security Mode,以及如何创建证书,请参见《WCF basicHttpBinding之Transport Security Mode, clientCredentialType="None"》,本文介绍如何使用Basic clientCredentialType。

server web.config

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindingConfig">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WCFDemo.DemoService" behaviorConfiguration="CustomBehavior">
<endpoint address="DemoService" binding="wsHttpBinding" contract="WCFDemo.IDemoService" bindingConfiguration="wsHttpBindingConfig" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CustomBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>

client app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDemoService">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://win-ounm08eqe64.henry.huang/DemoService.svc/DemoService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDemoService"
contract="DemoServiceReference.IDemoService" name="WSHttpBinding_IDemoService" />
</client>
</system.serviceModel>
</configuration>
public partial class Form1 : Form
{
DemoServiceReference.DemoServiceClient demoServiceClient; public Form1()
{
InitializeComponent();
demoServiceClient = new DemoServiceReference.DemoServiceClient();
demoServiceClient.ClientCredentials.UserName.UserName = "alex";
demoServiceClient.ClientCredentials.UserName.Password = "";
} private void buttonCalculate_Click(object sender, EventArgs e)
{
try
{
textBoxResult.Text = demoServiceClient.Divide(Convert.ToInt32(textBoxNumerator.Text), Convert.ToInt32(textBoxDenominator.Text)).ToString();
}
catch (FaultException<DemoServiceReference.DivideByZeroFault> fault)
{
MessageBox.Show(fault.Detail.Error + " - " + fault.Detail.Detail);
}
}
}

调用成功。

WCF wsHttpBinding之Transport security Mode, clientCredentialType=”Basic”的更多相关文章

  1. WCF basicHttpBinding之Transport Security Mode, clientCredentialType="None"

    原创地址:http://www.cnblogs.com/jfzhu/p/4071342.html 转载请注明出处 前面文章介绍了<WCF basicHttpBinding之Message Sec ...

  2. WCF basicHttpBinding之Message Security Mode

    原创地址:http://www.cnblogs.com/jfzhu/p/4067873.html 转载请注明出处 前面的文章<WCF Security基本概念>介绍了WCF的securit ...

  3. iOS App 不支持http协议 App Transport Security has blocked a cleartext HTTP (http://)

    目前iOS已经不支持http协议了,不过可以通过info.plist设置允许 App Transport Security has blocked a cleartext HTTP (http://) ...

  4. App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file

    ios进行http请求,会出现这个问题: App Transport Security has blocked a cleartext HTTP (http://) resource load sin ...

  5. App Transport Security has blocked a cleartext HTTP (http://)

    使用SDWebImage加载“http://”开头的图片报错,错误如下: App Transport Security has blocked a cleartext HTTP (http://) r ...

  6. iOS9中的App Transport Security

    问题:webView加载网页加载不出来 原因:苹果在iOS9 sdk中加入了App Transport Security限制(iOS9以前的iOS sdk默认关闭ATS),默认强制使用https,并且 ...

  7. 网络请求报错:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

    iOS9引入了新特性App Transport Security (ATS).详情:App Transport Security (ATS) 如果你想设置不阻止任何网络,只需要在info.plist文 ...

  8. IOS开发 App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

    xcode自7后不再使用http,而是使用https请求,但目前很多网络请求还只是以http请求,我们可以这样解决 info.plist->添加@“App Transport Security ...

  9. App Transport Security has blocked a cleartext

    错误描述: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecu ...

随机推荐

  1. 连接Mysql提示Can’t connect to local MySQL server through socket的解决方法

    mysql,mysqldump,Mysqladmin,php连接mysql服务常会提示下面错误: ERROR 2002 (HY000): Can't connect to local MySQL se ...

  2. CSS中的rem的换算

    rem好像也是一个相对大小的值,它是相对于根元素<html>,比如假设,我们设置html的字体大小的值为 html{font-size: 87.5%;}(也就是14px,这是twentyt ...

  3. 现场打印智能无线PDA安卓POS 条码识别、打印、数据采集销售开单收银管理软件

    现场打印安卓POS 条码识别.打印.数据采集管理软件 案例: 经营日化品牌,从事小型超市和日用品商店的批发配送业务. 公司以前的销售模式:三个业务员负责跑市场,每个人负责一个区域,平均每天每个人要去到 ...

  4. SOAPUI使用教程-REST功能测试

    当创造了SoapUI功能测试用例,常见的情况是,你调用一些REST资源和验证其响应检查返回正确的结果.这可以容易地实现: 添加一个REST请求到新的test step或现有的TestCase 添加断言 ...

  5. Time-travel Models

    1. Standard Iterative Branching model   Source Code   Butterfly Effect   Next   Edge of Tomorrow   D ...

  6. 基于lcov实现的增量代码UT覆盖率检查

    背景介绍 配合CppUTest单元测试框架,lcov提供了一套比较完整的工程工具来对UT覆盖率进行度量.但对有些团队来说,历史负担太重,大量的遗留代码没有相应的UT.在这种情况下,对新增代码进行覆盖率 ...

  7. hdu3068马拉车

    其实马拉车还真是最好理解的算法(感觉初中的时候好像讲过类似的,但是当时就没有认真听) 没想到一个简单的优化能变成O(n),感觉碉堡 不说了,马拉车裸题,我在写的时候只保留了id,没保留mx,希望能形成 ...

  8. 不错的 iOS 工具

    1.LSUnusedResources,移除不用图片资源

  9. nodejs 单元测试

    之前项目开发因为改进度,基本都是粗放式开发.为了提高代码质量,单元测试是必不可少的. 针对restful api ,用supertest 测试框架.针对nodejs,引入mocha 和should 可 ...

  10. fatal error

    1.   fatal error C1083: 无法打开源文件 编译报此错误:  1>c1xx : fatal error C1083: 无法打开源文件:“Projects\XXXCCCC\VB ...