time 
设为首页】【收藏本站
当前位置: 主页 > 程序设计 > .net > WCF > WCF basicHttpBinding使用Transport Security Mode和clientCredentialType="None"

WCF basicHttpBinding使用Transport Security Mode和clientCredentialType="None"

时间:2015-01-08 14:11 点击:2210次 字体:[ ]




前面文章介绍了http://www.fengfly.com/plus/view-215504-1.html如何basicHttpBinding的Message Security Mode,并且clientCredentialType用的是certificate。

本文演示basicHttpbinding使用Transport Security Mode,并且clientCredentialType="None"。

(一)WCF 服务代码与配置文件

IDemoService.cs

  1. using System.ServiceModel;  
  2.  
  3. namespace WCFDemo   
  4. {      
  5.     [ServiceContract(Name = "IDemoService")]   
  6.     public interface IDemoService   
  7.     {   
  8.         [OperationContract]   
  9.         [FaultContract(typeof(DivideByZeroFault))]   
  10.         int Divide(int numerator, int denominator);   
  11.     }   

DemoService.cs

  1. using System;   
  2. using System.ServiceModel;   
  3. using System.ServiceModel.Activation;  
  4.  
  5. namespace WCFDemo   
  6. {   
  7.     [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]   
  8.     public class DemoService : IDemoService   
  9.     {   
  10.         public int Divide(int numerator, int denominator)   
  11.         {   
  12.             try   
  13.             {   
  14.                 return numerator / denominator;   
  15.             }   
  16.             catch (DivideByZeroException ex)   
  17.             {   
  18.                 DivideByZeroFault fault = new DivideByZeroFault();   
  19.                 fault.Error = ex.Message;   
  20.                 fault.Detail = "Denominator cannot be ZERO!";   
  21.                 throw new FaultException<DivideByZeroFault>(fault);   
  22.             }             
  23.         }   
  24.     }   

完整的代码也可以参见http://www.fengfly.com/plus/view-215500-1.html 

server web.config

  1. <?xml version="1.0"?>   
  2. <configuration>   
  3.     <system.web>   
  4.       <compilation debug="true" targetFramework="4.0" />   
  5.     </system.web>   
  6.     <system.serviceModel>   
  7.       <bindings>   
  8.         <basicHttpBinding>   
  9.           <binding name="basicBinding">   
  10.             <security mode="Transport">   
  11.               <transport clientCredentialType="None" />   
  12.             </security>   
  13.           </binding>   
  14.         </basicHttpBinding>   
  15.       </bindings>   
  16.       <services>   
  17.         <service name="WCFDemo.DemoService" behaviorConfiguration="CustomBehavior">   
  18.           <endpoint address="DemoService" binding="basicHttpBinding" contract="WCFDemo.IDemoService" bindingConfiguration="basicBinding" />            
  19.           <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>   
  20.         </service>   
  21.       </services>   
  22.         <behaviors>   
  23.             <serviceBehaviors>   
  24.                 <behavior name="CustomBehavior">   
  25.                     <serviceMetadata httpsGetEnabled="true" />   
  26.                     <serviceDebug includeExceptionDetailInFaults="false" />                      
  27.                 </behavior>   
  28.             </serviceBehaviors>   
  29.         </behaviors>   
  30.         <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />   
  31.     </system.serviceModel>   
  32. </configuration> 



本文地址 : http://www.fengfly.com/plus/view-215505-1.html
标签: WCF Transport Security Mode clientCredentialType basicHttpBinding
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码: