WCF:调用方未由服务器进行身份验证

在使用wsHttpBinding方式,且又没有安全验证的情况下客户端调用服务会报:调用方未有服务器进行身份验证的异常。

原因:wsHttpBinding默认为安全认证模式,排除此异常只需要修改配置文件,在wsHttpBinding配置中添加<security mode="None"/>即可。 

 1 <system.serviceModel>
 2     <services>
 3     <service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
 4      <!-- Service Endpoints -->
 5      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoneSecurity" contract="WcfService2.IService1">
 6       <identity>
 7        <dns value="localhost"/>
 8       </identity>
 9      </endpoint>
10      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
11     </service>
12    </services>
13     <bindings>
14       <wsHttpBinding>
15         <binding name="NoneSecurity"
16           maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
17           <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
18           <!--服务端和客户端都需要添加-->
19           <security mode="None"/>
20         </binding>
21       </wsHttpBinding>
22     </bindings>
23    <behaviors>
24     <serviceBehaviors>
25      <behavior name="WcfService2.Service1Behavior">
26       <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->
27       <serviceMetadata httpGetEnabled="true"/>
28       <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
29       <serviceDebug includeExceptionDetailInFaults="false"/>
30      </behavior>
31     </serviceBehaviors>
32    </behaviors>
33 </system.serviceModel>
34 </configuration>
Web.config
原文地址:https://www.cnblogs.com/yf2011/p/4980939.html