原创地址: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. Drools 函数学习

    Drools 函数学习 函数是定义在规则文件当中一代码块,作用是将在规则文件当中若干个规则都会用到的业务操作封装起来,实现业务代码的复用,减少规则编写的工作量.函数的编写位置可以是规则文件当中 pac ...

  2. [原创] Go语言在Centos上的部署

    序言 Golang是个好东西啊.部署非常简单,对于运维人员来说太爽了. 传统的Nginx啊Apache啊,外加PHP以及各个插件啊搞得头晕. 用了Go之后就什么都不需要了.只要把生成好的文件向服务器上 ...

  3. JMeter执行dos命令

    1.通过java代码实现 参考Java实现操作dos命令 2.直接通过JMeter内置的beanshell脚本操作 String command = "cmd /c start ping w ...

  4. Unity 依赖注入之一

    在项目中引入Unity,建立一个接口IWork跟一个继承IWork接口的Work类 public interface IMyWork { void Work(); } public class MyW ...

  5. 使用echarts开发电子屏数据展示页面

    背景 之前的项目因为要顾及体量问题,选用了highchart,没用上echarts:这次因为是本地部署电子屏幕的展示页,不需要考虑体量大小,直接用上了echarts:用起来觉得非常不错,特别是地图上非 ...

  6. Linux SHELL 命令入门题目(一)

    新年新气象,注重知识积累,提高手敲代码能力,而不是眼高手低,只会复制黏贴. 1.使用shell 打印 “Hello World!” 2.求变量'hello world'的字符长度 3.$0 .$SHE ...

  7. js中获取css的样式

    因为给定一个div宽度或者其他样式之后,再设置一个border的宽度在js中得到的obj.setoffWidth就会变成width加上border的二倍宽度,因此可以自己写一个方法来获取样式.(obj ...

  8. make工作时的执行步骤

    GNU的make工作时的执行步骤 (1)读入所有的Makefile (2)读入被include的其它Makefile (3)初始化文件中的变量 (4)推导隐晦规则,并分析所有的规则 (5)为所有的目标 ...

  9. Flask_more1

    #DB ``` import os basedir = os.path.abspath(os.path.dirname(__file__))   SQLALCHEMY_DATABASE_URI = ' ...

  10. BZOJ4293: [PA2015]Siano

    Description 农夫Byteasar买了一片n亩的土地,他要在这上面种草. 他在每一亩土地上都种植了一种独一无二的草,其中,第i亩土地的草每天会长高a[i]厘米. Byteasar一共会进行m ...