原创地址: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. T-SQL 递归

    WITH TEMP ([ID], [PARENTID]) AS (SELECT UNIQUEID ,PID FROM [DBO].TB_DEPTINFO D WHERE PID = @ParentId ...

  2. JMeter中HTTP Cookie 管理器使用

    案例: 在一次做公司OA系统的时候,发现录制脚本无法回放成功,通过定位,是因为登录的过程中存在重定向,导致登录接口的状态没有自动带入重定向页面 解决方法: 加入HTTP Cookie 管理器使用 现象 ...

  3. java调用sqlldr oracle 安装的bin目录

    package com.jyc.sqlldr; import java.io.BufferedReader;import java.io.InputStream;import java.io.Inpu ...

  4. win 文字转化为语音

    mshta vbscript:createobject("sapi.spvoice").speak("hello")(window.close)

  5. 2015 ACM/ICPC EC-Final

    A. Boxes and Balls 二分找到最大的不超过$n$的$\frac{x(x+1)}{2}$形式的数即可. #include <bits/stdc++.h> using name ...

  6. android 5.0以上通知栏、状态栏图标变成白色

    在5.0以上的系统上发现,平常的自定义notification出来的icon,居然在状态栏上变成了纯白色的icon. 看源代码会发现: protected void applyColorsAndBac ...

  7. android 常用URI

    关于联系人的一些URI: 管理联系人的Uri: ContactsContract.Contacts.CONTENT_URI 管理联系人的电话的Uri: ContactsContract.CommonD ...

  8. 从倒影说起,谈谈 CSS 继承 inherit(转)

    从倒影说起,谈谈 CSS 继承 inherit 给定一张有如下背景图的 div: 制作如下的倒影效果: 方法很多,但是我们当然要寻找最快最便捷的方法,至少得是无论图片怎么变化,div 大小怎么变化,我 ...

  9. 中文字符匹配js正则表达式

    普遍使用的正则是[\u4e00-\u9fa5],但这个范围并不完整.例如:  /[\u4e00-\u9fa5]/.test( '⻏' ) // 测试部首⻏,返回false    根据Unicode 5 ...

  10. 关于UIScrollerView的基本用法和代理

    - (void)viewDidLoad { [super viewDidLoad];  scrollView = [[UIScrollView alloc] initWithFrame:CGRectM ...