WCF开发简简单单的六个步骤

上传人:夏** 文档编号:458233158 上传时间:2022-08-27 格式:DOC 页数:5 大小:44KB
返回 下载 相关 举报
WCF开发简简单单的六个步骤_第1页
第1页 / 共5页
WCF开发简简单单的六个步骤_第2页
第2页 / 共5页
WCF开发简简单单的六个步骤_第3页
第3页 / 共5页
WCF开发简简单单的六个步骤_第4页
第4页 / 共5页
WCF开发简简单单的六个步骤_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《WCF开发简简单单的六个步骤》由会员分享,可在线阅读,更多相关《WCF开发简简单单的六个步骤(5页珍藏版)》请在金锄头文库上搜索。

1、在这里我就用一个据于一个简单的场景:服务端为客服端提供获取客户信息的一个接口读取客户信息,来完成WCF开发入门的六个步骤。1.定义WCF服务契约A. 项目引用节点右键添加System.ServiceModel弓I用。在代码文件里,添加以下命名空间的引用usingSystem.ServiceModel;usingSystem;新建一个命为ICustomerService接口,并添加一个获取客户信息的方法定义名为Customerinfomation,返回字符串类型的客户信息。B. 为接口ICustomerService添加ServiceContract的属性修饰使它成为WCF服务中公开的接口。为方

2、法Customerinfomation添加Operationcontract的属性修饰使它成为WCF服务公开接口中公开的成员。F代码:usingSystem;2usingSystem.ServiceModel;4namespaceConWCF6ServiceContract(Namespace=)8publicinterfaceCustomerService101112OperationContract14StringCustomerinformation();1618202.实现WCF服务契约1usingSystem;2usingSystem.ServiceModel;5namespaceC

3、onWCF6ServiceContract(Namespace=)8publicinterfaceICustomerService1112Operationcontract14StringCustomerInformation();1618publicclassCustomerService:ICustomerService202122#regionICustomerService成员24publicstringCustomerInformation()2628return这是客户的信息!;3032#endregion3436383.启动WCF服务B. 配置WCF服务的基本地址,如下所示C.

4、配置WCF服务的端口。Address=“,”意思就是使用上面配置的基本地址,当然也可以在这里指定。Bingding=“wsHttpBinding意思是WCF服务使用的是HTTP协议。再接下来就是配置WCF服务契约了(命名空间.服务契约接口名),如下所示:D. 配置文件E. 启动服服就简单了ServiceHosthost=newServiceHost(typeof(CustomerService);host.Open();Console.WriteLine(客户信息服务已启动);Console.WriteLine(按任意键结束服务!);Console.Read();host.Close();F.

5、 当服务启动时,在IE栏中输入:http:/localhost:8000/conwcfr,将会收到一些帮助的提示信息。G. 异常:配置文件中的服务名称一定是:命名空间.实现WCF服务契约类的名称,否则将会发生找到不配置的异常。svcutil/language:c#/out:CustomerClient.cs/config:app.confighttp:/localhost:8000/conwcfr上面命令指定了要生成代码的语言,代码文件和配置文件名,WCF服务端地址,注意运行命令时必须确定WCF服务端正在运行中。5. WCF客服端基本配置WCF客户端配置就是配置调用WCF服务端的协议,输传宽带

6、,服务地址,安全等等信息。下面就上一步骤命令自动生成的配置文件。12vreaderQuotasmaxDepth=32maxStringContentLength=8192maxArrayLength=1638413maxBytesPerRead=4096maxNameTableCharCount=16384/14vreliableSessionordered=trueinactivityTimeout=00:10:0015enabled=false/16vsecuritymode=Message17vtransportclientCredentialType=WindowsproxyCrede

7、ntialType=Nonerealm=/vmessageclientCredentialType=WindowsnegotiateServiceCredential=truealgorithmSuite=DefaultestablishSecurityContext=true/vendpointaddress=http:/localhost:8000/conwcfrbinding=wsHttpBindingbindingConfiguration=WSHttpBindingCustomerservicecontract=ICustomerServicename=WSHttpBinding_I

8、CustomerServicevuserPrincipalNamevalue=30DA1D0B1D1E4D2Administrator/34 6.使用WCF客户端1. 在客户端项目中项目引用节点右键添加System.ServiceModel引用.2. 添加第四部中创建的客户端代码文件和配置文件。客户端调用服务端的服务,只要创建生成客户端类的实例就可调用了,但要确认服务端正在起用状态,如下usingSystem;2namespaceConWCFCustomerClient41 classProgram凋-10staticvoidMain(stringargs)13口14 I15ICustomerServiceClientclient=new16Istringmessage=client.Customerlnformation();I191Console.WriteLine(message);I|Console.Read();I23=|2627L

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号