WCF发布到IIS 7.0,并以https访问

一、IIS 7.0中如何生成服务器证书,并要求网站以http访问可参考:

http://www.cnblogs.com/chnking/archive/2008/10/07/1305811.html 

     这里一定要保证证书名字与服务器名完全相同

二、WCF应用程序制作

1.“新建项目”---WCF服务应用程序;

2.修改服务接口及服务类,生成;

3.如果不考虑安全,到这里直接发布,客户端就可以调用了;

三、 WCF服务配置编辑器

1. 使用“WCF服务配置编辑器”打开该程序的web.config 

2. 新建"服务":

(1)选择生成好的”.dll"

(2)通信模式有好几种:TCP、HTTP、命名管道、MSMQ、对等(点对点),

(3)不考虑事务、就用基本Web服务操作性;

(4)终结点地址(可以不填,后面可能需要看下这个具体配置) 

3.新建"绑定“:

 (1)basicHttpBinding

 (2)切换到”安全性“

 (3)Mode选“Transport",然后设置TransportSecurity属性中的TransportClientCredentialType为"none"

4.高级中的服务行为:

 (1)给个名字:命名空间.ServiceBehavior(不是固定的,只是觉得这样写挺规范的);

 (2)对于"serviceMetaData" 元数据,设置"HttpGetEnabled=false,HttpsGetEnabled=true",

 (3)应用服务行为设置,选中在步骤2中设置好的服务,“BehaviorConfiguration"中为(1)设定的名字,”终结点“中的”BindingConfiguration"要

选择在步骤3中的绑定名称

5.发布到WCF上:

 

6.用https测试WCF服务:

   唯一要注意的是localhost替换成本机名

7.使用添加“服务引用”或Svcutil生成客户端,前提是:保证IIS_USER用户对C:\Windows\Temp目录有权限

8.生成客户端后:

            string url = "https://myeggsoft/MyWcfService/DataService.svc";

            BasicHttpBinding myBinding = new BasicHttpBinding();
            myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
            myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            EndpointAddress address = new EndpointAddress(url);
            ServiceReference1.DataServiceClient client = new ServiceReference1.DataServiceClient(myBinding, address)
            ...... 

     

 

 

 

 

 

 

posted @ 2012-07-02 15:32  阿土仔  阅读(4108)  评论(0编辑  收藏  举报