WCF问题:找不到具有绑定 WSHttpBinding 的终结点的与方案 http 匹配的基址。注册的基址方案是 [https]"错误

在.net4.0下WCF程序默认是不对客户端进行身份验证。而在.net3.5下WCF程序默认是对客户端进行windows身份验证。所有如果不在同一个域中.net3.5下的WCF访问会失败,报"调用方未由服务进行身份验证",因为不在同一个域中验证会失败。

 

现在修改配置文件然.net4.0下的WCF也进行windows身份验证,因为进行身份验证就可以获取客户端的登录名等信息。

配置文件如下

[c-sharp] view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <configuration>  
  3.   
  4.   <system.web>  
  5.     <authentication mode="Windows"/>  
  6.     <compilation debug="true" targetFramework="4.0" />  
  7.   </system.web>  
  8.   <system.serviceModel>  
  9.       
  10.     <services>  
  11.       <service name="WcfService3.Service1" behaviorConfiguration="WcfService3.Service1Behavior">  
  12.         <!-- Service Endpoints -->  
  13.         <host>  
  14.           <baseAddresses>  
  15.             <add baseAddress="http://localhost/"/>  
  16.           </baseAddresses>  
  17.         </host>  
  18.         <endpoint address="" binding="wsHttpBinding" bindingConfiguration="userHttp"  contract="WcfService3.IService1">  
  19.           <!--   
  20.               部署时,应删除或替换下列标识元素,以反映  
  21.              用来运行所部署服务的标识。删除之后,WCF 将  
  22.               自动推断相应标识。  
  23.           -->  
  24.           <identity>  
  25.             <dns value="localhost"/>  
  26.           </identity>  
  27.         </endpoint>  
  28.         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>  
  29.       </service>  
  30.     </services>  
  31.     <bindings>  
  32.       <wsHttpBinding>  
  33.         <binding name="userHttp">  
  34.             
  35.           <security mode="Transport">  
  36.             <transport clientCredentialType="Windows"></transport>  
  37.           </security>  
  38.         </binding>  
  39.       </wsHttpBinding>  
  40.     </bindings>  
  41.     <behaviors>  
  42.       <serviceBehaviors>  
  43.         <behavior name="WcfService3.Service1Behavior">  
  44.           <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->  
  45.           <serviceMetadata httpGetEnabled="true"/>  
  46.           <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->  
  47.           <serviceDebug includeExceptionDetailInFaults="true"/>  
  48.         </behavior>  
  49.       </serviceBehaviors>  
  50.     </behaviors>  
  51.     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />  
  52.   </system.serviceModel>  
  53.  <system.webServer>  
  54.     <modules runAllManagedModulesForAllRequests="true"/>  
  55.   </system.webServer>  
  56.     
  57. </configuration>  

使用这个配置文件就出现了“WCF问题:找不到具有绑定 WSHttpBinding 的终结点的与方案 http 匹配的基址。注册的基址方案是 [https]"错误。

原因是security模型使用了Transport,如: <security mode="Transport">。Transport模型下是需要使用ssl和证书的,访问也是使用https。所有会报“注册的基址方案是 [https]"错误。只需要把安全模型修改为以下代码就可以

[c-sharp] view plain copy print ?
  1. <binding name="userHttp">  
  2.    <security mode="Message" >  
  3.      <message clientCredentialType="Windows"/>  
  4.    </security>  
  5.      
  6.  </binding>  

获取客户端信息:

[c-sharp] view plain copy print ?
  1. OperationContext context = OperationContext.Current;  
  2.             MessageProperties messageProperties = context.IncomingMessageProperties;  
  3.             RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;  
  4.             string address = endpointProperty.Address;  
  5.             string name = ServiceSecurityContext.Current.WindowsIdentity.Name;  

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值