惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
A
Arctic Wolf
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threatpost
P
Proofpoint News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Vulnerabilities – Threatpost
V
V2EX
Webroot Blog
Webroot Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
T
Tor Project blog
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Vercel News
Vercel News
Security Archives - TechRepublic
Security Archives - TechRepublic
MongoDB | Blog
MongoDB | Blog
T
Troy Hunt's Blog
Google DeepMind News
Google DeepMind News
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
Y
Y Combinator Blog
T
Threat Research - Cisco Blogs
S
Security Affairs
Google Online Security Blog
Google Online Security Blog
S
Securelist
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
爱范儿
爱范儿
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
AWS News Blog
AWS News Blog

博客园 - Animax!

The Tao of Programming Light weight Framework (AnyBase) -- 通信模块说明 关于WinIO.DLL的键盘输入模拟 Light weight Framework (AnyBase) -- Core 模块说明 开源项目 Light weight Framework (AnyBase) 发布 DB4o的缓存机制 Winfrom界面异步操作的一个解决方法 db4o 研究--性能测试 Asp.net动态数据(Dynamic Data) 笔记一 MVC — 笔记 WF笔记 – Workflow概念 WCF Demo – Http、TCP Host - Animax! LINQ TO SQL 笔记 — 存储过程、并发与事务 WCF 笔记 正则表达式[转载整理] - Animax! - 博客园 LINQ 笔记 - LINQ to SQL 基本数据操作 - Animax! LINQ 笔记 - 语法与关键字 LINQ 笔记- Lambda Excel导入SQL - Animax! - 博客园
WCF笔记 - 绑定
Animax! · 2008-04-16 · via 博客园 - Animax!

2008-04-16 14:22  Animax!  阅读(1414)  评论()    收藏  举报

【此文是纯碎的笔记(无逻辑的,松散的)】

WCF中常用的binding方式:

BasicHttpBinding: 用于把 WCF 服务当作 ASMX Web 服务。用于兼容旧的Web ASMX 服务。
WSHttpBinding:
BasicHttpBinding 更加安全,通常用于 non-duplex 服务通讯。
WSDualHttpBinding:
WSHttpBinding 相比,它支持 duplex 类型的服务。
WSFederationHttpBinding: WS-Federation
安全通讯协议。
NetTcpBinding:
使用 TCP 协议,用于在局域网(Intranet)内跨机器通信。有几个特点:可靠性、事务支持和安全,优化了 WCF WCF 的通信。限制是服务端和客户端都必须使用 WCF 来实现。
NetNamedPipeBinding:
使用命名管道进行安全、可靠、高效的单机服务通讯方式。
NetMsmqBinding:
使用消息队列在不同机器间进行非连接通讯。
NetPeerTcpBinding:
使用 P2P 协议在多机器间通讯。
MsmqIntegrationBinding:
WCF 消息转化为 MSMQ 消息,使用现有的消息队列系统进行跨机器通讯。如 MSMQ

名称

传输

编码

共同操作

BasicHttpBinding

HTTP/HTTPS

Text

Yes

NetTcpBinding

TCP

Binary

No

NetPeerTcpBinding

P2P

Binary

No

NetNamedPipeBinding

IPC

Binary

No

WSHttpBinding

HTTP/HTTPS

TextMTOM

Yes

WSFederationBinding

HTTP/HTTPS

TextMTOM

Yes

WSDualHttpBinding

HTTP

TextMTOM

Yes

NetMsmqBinding

MSMQ

Binary

No

MsmqIntegrationBinding

MSMQ

Binary

Yes

Binding名称

Configuration Element

描述

BasicHttpBinding

basicHttpBinding

一个指定用符合基本网络服务规范通讯的binding,它用http进行传输,数据格式为text/xml

WSHttpBinding

wsHttpBinding

一个安全的通用的binding,但它不能在deplex中使用

WSDualHttpBinding

wsDualHttpBinding

一个安全的通用的binding,但能在deplex中使用

WSFederationHttpBinding

wsFederationHttpBinding

一个安全的通用的支持WSFbinding,能对用户进行验证和授权

NetTcpBinding

netTcpBinding

wcf应用程序中最适合跨机器进行安全通讯的binding

NetNamedPipeBinding

netNamedPipeBinding

wcf应用程序中最适合本机进行安全通讯的binding

NetMsmqBinding

netMsmqBinding

wcf应用程序中最适合跨机器进行安全通讯的binding,并且支持排队

NetPeerTcpBinding

netPeerTcpBinding

一个支持安全的,多机交互的binding

MsmqIntegrationBinding

msmqIntegrationBinding

一个用于wcf与现有msmq程序进行安全通讯的binding

绑定类名称

传输

消息编码

消息版本

安全模式

可靠消息传送

事务流(默认情况下禁用)

BasicHttpBinding

HTTP

文本

SOAP 1.1

不支持

不支持

WSHttpBinding

HTTP

文本

SOAP 1.2 WS-Addressing 1.0

消息

禁用

WS-AtomicTransactions

WSDualHttpBinding

HTTP

文本

SOAP 1.2 WS-Addressing 1.0

消息

启用

WS-AtomicTransactions

WSFederationHttpBinding

HTTP

文本

SOAP 1.2 WS-Addressing 1.0

消息

禁用

WS-AtomicTransactions

NetTcpBinding

TCP

二进制

SOAP 1.2

传输

禁用

OleTransactions

NetPeerTcpBinding

P2P

二进制

SOAP 1.2

传输

不支持

不支持

NetNamedPipesBinding

命名管道

二进制

SOAP 1.2

传输

不支持

OleTransactions

NetMsmqBinding

MSMQ

二进制

SOAP 1.2

消息

不支持

不支持

MsmqIntegrationBinding

MSMQ

不支持(使用 WCF 之前的序列化格式)

不支持

传输

不支持

不支持

CustomBinding

您决定

您决定

您决定

您决定

您决定

您决定

可以通过修改WCF配置文件来修改binding的方式,修改WCF配置文件可以使用VS自带的WCF配置修改工具(WCF Service Configuration Editor

这里写一个配置文件的注释,这份是一个Service端的配置文件(不是Host,所以能公开元数据)。

<!-- Service端的配置文件,公开元数据与Http连接 -->

    <system.serviceModel>                                     WCF 配置开始

        <behaviors>                                           一个服务器行为的配置开始

            <serviceBehaviors>                                

                <behaviorname="NewBehavior">                 配置一个行为 name:行为的名称

                    <serviceDebug />                          表示此service可以调试     

                    <serviceMetadatahttpGetEnabled="true"httpsGetEnabled="false" />

                    元数据的配置, httpGetEnabled:是否可以使用Http来获取元数据,

httpsGetEnabled:是否可以使用Https来获取元数据

                    当设置为可以获取元数据, 就必须配置http或https的路径

                </behavior>

            </serviceBehaviors>

        </behaviors>                                          服务器行为配置结束

        <services>                                            服务器配置开始      

          <service behaviorConfiguration="NewBehavior"       配置一个服务器, behaviorConfiguration:指示服务行为,b连接到behaviors

                     name="Service">   name:服务类的位置

            <endpoint                                         开始一个端口的配置

                   binding="basicHttpBinding"                 binding: 绑定类型 Http

                   contract=" IShopServiceV2" >

                                                              contract:公共接口的位置

            </endpoint>

            <endpoint                         开始第二个端口的配置,这个端口是用于发布元数据

                    address="mex"             address:端口的监听位置,mex表示设置成相对地址

                    binding="mexHttpBinding"                  binding: 绑定方式.

                                                             此处为元数据的绑定方式

                                                     mexHttpBinding(对于 HTTP 发布)。

                                                     mexHttpsBinding(对于 HTTPS 发布)。

                                                     mexNamedPipeBinding(对于命名管道发布)。

                                                     mexTcpBinding(对于 TCP 发布)。

                    contract="IMetadataExchange"/>            contract:公共接口的位置

                                      IMetadataExchange: 公开用于返回有关服务的元数据的方法

            <host>                                            主机配置

                <baseAddresses>                               

                    <addbaseAddress="http:127.0.0.1:8001/WCFService" />

                                                              配置一个服务器的监听路径

                </baseAddresses>

            </host>

          </service>

        </services>

代理类生成:不单是WCF服务文件(.svn)能用工具(svcutil.exe)来生成客户端代理,即使使用WCF服务库也可以通过WCF服务主机的元数据地址来使用svcutil.exe生成代理。

一个双绑定,带配置文件的HostDemo

 <system.serviceModel>

    <services>

      <servicename="Service">

        <endpointbinding="netTcpBinding"contract="IShopServiceV2" />

        <endpointbinding="basicHttpBinding"contract="IShopServiceV2" />

      </service>

    </services>

 </system.serviceModel>

                Uri tcpAddress = new Uri("net.tcp://localhost:9000/Service");

                Uri httpAddress = new Uri("http://localhost:9001/Service");

                ServiceHost Host = new ServiceHost(typeof(WCFCompnent.Service), tcpAddress, httpAddress);

                Host.Open();

                Console.WriteLine("服务已经启动!");

                Console.Read();

                Host.Close();

不带配置文件的Host

            Uri baseAddress = new Uri("net.tcp://localhost:9000/ServoceHost");

            Uri mexAddress = new Uri("mex", UriKind.Relative);

            using (ServiceHost serviceHost = new ServiceHost(typeof(Service), baseAddress))

            {

                NetTcpBinding binding = new NetTcpBinding();

                serviceHost.AddServiceEndpoint(typeof(PublicElements.publicInterface.IService), binding, baseAddress);

                serviceHost.Open();

                Console.WriteLine("服务器已经打开");

                Console.WriteLine("按任意键关闭");

                Console.Read();

                serviceHost.Close();

            }