IIS——WCF http服务修改为https服务

一、IIS配置

  1. 保证IIS拥有配置https的功能
    在windows 功能中将IIS的所有功能开启即可。

  2. 生成证书(标准企业需去平台申请证书,本文介绍开发自设置)在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

  3. 添加网站
    在这里插入图片描述

  4. 测试
    用IE打开,google等浏览器会直接打不开。在这里插入图片描述

二、配置文件修改

  1. WebService Config

    1.endingpoint 配置:
    	源数据交换: mexHttpBinding -> mexHttpsBinding
    	
    	否则报错:
    		找不到具有绑定 MetadataExchangeHttpBinding 的终结点的与方案 http 匹配的基址。注册的基址方案是 [https]...
    
    
    		
    2.binding
    	1) wsHttpBinding 配置
    		<security mode="Message" >    -> 	<security mode="Transport" >
    		否则报错:
    			WCF问题:找不到具有绑定 WSHttpBinding 的终结点的与方案 http 匹配的基址。注册的基址方案是 [https]"错误
    
    	2) httpTransport -> httpsTransport
    
    3.Behavior
     <serviceMetadata httpGetEnabled="true" /> -> <serviceMetadata httpsGetEnabled="true" />
    
    
  2. Client Config

    1.binding配置:
    	1) <security mode="Message" >    -> 	<security mode="Transport" >
    	
    	2) httpTransport -> httpsTransport
    

3.注意点

要保证客户端和服务端的 mode 类型一直,否则会报如下错误。

The content type text/html of the response message does not match the content type of the binding (application/x-gzip). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:

三、查看wcf服务

忽略证书即正常出结果。在这里插入图片描述

四、客户端连接wcf服务

  1. 可能出现的问题
    Could not establish trust relationship for the SSL/TLS secure channel with authority.
    在client连接wcf创建通道的代码前增加如下代码即可:

    ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    
    IClientChannel channel = GetChannelFactory(endPoint).CreateChannel() as IClientChannel;  //创建通道代码
    
  2. 解决完上面的问题即可正常连接登录

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在 Visual Studio 中创建 WCF 服务库项目时,确实不会自动生成 .svc 文件。这是因为 WCF 服务库项目是一种库项目,而不是一种应用程序项目。 在 WCF 服务库项目中,您需要手动创建一个托管服务的应用程序。这个应用程序可以是一个控制台应用程序、一个 Windows 服务或一个 Web 应用程序。在这个托管应用程序中,您需要手动配置服务终结点,以便客户端可以连接到您的 WCF 服务。 在这种情况下,您可以手动创建一个 .svc 文件,并将其添加到您的托管应用程序中。在 .svc 文件中,您需要指定服务名称和服务实现类。例如: ``` <%@ ServiceHost Language="C#" Debug="true" Service="MyServiceNamespace.MyServiceClass" %> ``` 其中,“MyServiceNamespace”是指您的服务实现类所在的命名空间,“MyServiceClass”是指您的服务实现类的名称。 当您将 .svc 文件添加到托管应用程序中后,您需要在应用程序的配置文件中配置服务终结点。这个终结点应该指向您的 .svc 文件。例如: ``` <endpoint address="http://localhost/MyService.svc" binding="basicHttpBinding" contract="MyServiceNamespace.IMyService" /> ``` 这个终结点将客户端连接到您的 WCF 服务。注意,这个终结点中的服务地址应该与 .svc 文件的名称相匹配。 总之,虽然 WCF 服务库项目没有自动生成 .svc 文件,但您可以手动创建 .svc 文件,并将其添加到托管应用程序中,从而成功部署 WCF 服务

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值