当前位置:网站首页>WCF 入门教程二
WCF 入门教程二
2022-07-26 07:20:00 【51CTO】
作者:jiankunking
基本知识:
[ServiceContract] Attribute 可以有以下Property 的:
CallbackContract 设置callback的类型:Duplicate指Service Host和Client之间进行双向通信
ConfigurationName 指定配置文件中某个configuration的名字
HasProtectionLevel 标示是否可以处理安全消息
Name 给contract指定一个名字,在client端可见的名字,默认就是接口名字
Namespace 给消息指定一个命名空间
ProtectionLevel
SessionMode 指允许,还是不允许,还是强制session
[OperationContract] Attribute 可以有以下Property 的:
Action 对请求设置WS-Addressing 的action
AsynchPattern 异步模式
HasProtectionLevel 消息是否加密,签名
IsInitiating 表明该函数被调用开始时是否要在server上面初始化一个session
IsOneWay 表明函数被client调用以后,client是否会等待函数返回
IsTerminating 表明该函数被调用结束时是否要在server上面关闭session
Name 设置函数的名字,在client端可见的名字,默认就是函数名字
ProtectionLevel
ReplyAction 设置函数返回消息的SOAP action
1、 在网上看资料会看到各种给ServiceContract的Namespace、Name等属性赋值的代码,但这些Attribute 是在哪里起作用呢?

下面就让我们一起来看看,打开上篇中的解决方案WcfFirstDemo.sln
右键WCFServiceDemo项目下面的文件:Test..svc,如下图:

效果如下:

点击红框中的链接,效果如下:

可以看到默认Namespace是http://tempuri.org/,name与类名一致
微软官方建议:修改Service的Namespace,使其包含:公司域名+项目名+版本号(如:日期表示版本号)
小注:

修改项目:WCFServiceDemo下面的ITest.cs代码如下:
右键项目WCFServiceDemo选择重新编译,成功以后,重新用浏览器打开
ITest.svc,得到如下图:

此时已经改变了Service默认的Namespace了,重新生成一下部署包,部署到服务器上,然后更新一下client端,然后重新编译整个解决方案,会报错如下:

此时ServiceContract的那么已经改成JianKunKing而不是之前的Test了,如下图:

修改完错误后,浏览一下client端的app.config文件,如下,可以看到bindingConfiguration、contract、name等属性都已经修改了

可以与修改之前的app.config文件对比一下:

由此看见ServiceContract的Namespace、Name等等属性,可以起到重命名的作用,隐藏掉服务端类的真实信息,客户端看到的是你想让其看到的
ServiceContract做的工作是指定service向client提供了哪些函数可供调用。
边栏推荐
- Solve the problem that Chrome browser is tampered with by drug bullies
- NFT digital collection system development: Huawei releases the first collector's digital collection
- Manifest merger failed with multiple errors, see logs
- How to delete a statement audit log?
- QT: list box, table, tree control
- [yiku] wonderful! This library organization NPM script is simply explosive!
- NFT数字藏品系统开发:数字藏品赋予品牌新活力
- I don't understand the MySQL 57 version under centos7 when I encounter a problem. I was informed by big Shen who knows it
- NFT数字藏品系统开发:NFT数藏 的最佳数字营销策略有哪些
- Orthogonality of 20220724 trigonometric function system
猜你喜欢

404 page best practices to improve user experience

College degree sales career, from the third tier 4K to the first tier 20k+, I am very satisfied with myself

Advanced Mathematics (Seventh Edition) Tongji University General exercises two person solution

Apache dolphin scheduler & tidb joint meetup | focus on application development capabilities under the development of open source ecosystem

C51与MDK共存 Keil5安装教程

Lite actor: lightweight optimization of ark actor concurrency model

成为 Apache 贡献者,So easy!

Countdown 2 days! Based on the cross development practice of Apache dolphin scheduler & tidb, you can greatly improve your efficiency from writing to scheduling

6. Backup and recovery of MySQL database

NFT digital collection system development: Huawei releases the first collector's digital collection
随机推荐
Taishan Office Technology Lecture: page width, height, size and source, and the conversion relationship between inches, centimeters and DPI
成为 Apache 贡献者,So easy!
HCIP --- MPLS技术
Unity3d asynchronous loading of scenes and progress bar loading
NFT数字藏品系统开发:NFT数藏 的最佳数字营销策略有哪些
How can man Bang write a new footnote to the value of the industry's first social responsibility report?
From scratch, we will completely develop an online chess game [Gobang] Based on websocket, and only use dozens of lines of code to complete all the logic.
Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV
正则表达式如何写变量
Unity3d-异步加载场景、进度条加载
Image annotation software reference
Event loop in browser
Drools (4): drools basic syntax (2)
Precious metal knowledge: lethal short-term secret script
Idea -- use @slf4j to print logs
Why can't extern compile variables decorated with const?
Relevant configurations of pychart: change font style and size, change picture background, and change the font color of console output
NFT digital collection system development: Huawei releases the first collector's digital collection
C51 and MDK coexist keil5 installation tutorial
QT: modal, modeless, text box, button, single line input box