WCF无身份验证配置

服务器端配置

<?xml version="1.0"?> <configuration>   <configSections>     <section name="MoreBusinessDatabase" type="mccn.Pureview.DBEntity.MoreBusinessDatabaseSection,mccn.Pureview.DBEntity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2f4505df9c822944"/>   </configSections>          <system.web>     <compilation debug="true"/>   </system.web>   <!-- 部署服务库项目时,必须将配置文件的内容添加到   主机的 app.config 文件中。System.Configuration 不支持库的配置文件。-->   <system.serviceModel>   <bindings>             <wsHttpBinding>                 <binding name="NoneSecurity" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">                     <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>                     <security mode="None"/>                 </binding>             </wsHttpBinding>         </bindings>



    <services>       <service name="mccn.Pureview.WCFBusinessService.PureviewService">         <endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoneSecurity"  contract="mccn.Pureview.WCFBusinessService.IPureviewService">           <identity>             <dns value="localhost"/>           </identity>         </endpoint>         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>         <host>           <baseAddresses>             <add baseAddress="http://localhost:8002/Design_Time_Addresses/mccn.Pureview.WCFBusinessService/Service1/"/>           </baseAddresses>         </host>       </service>     </services>     <behaviors>       <serviceBehaviors>         <behavior>           <!-- 为避免泄漏元数据信息,           请在部署前将以下值设置为 false 并删除上面的元数据终结点  -->           <serviceMetadata httpGetEnabled="True"/>           <!-- 要接收故障异常详细信息以进行调试,           请将以下值设置为 true。在部署前设置为 false             以避免泄漏异常信息-->           <serviceDebug includeExceptionDetailInFaults="False"/>         </behavior>       </serviceBehaviors>     </behaviors>   </system.serviceModel>

   <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> </configuration>


其中

<bindings>
            <wsHttpBinding>
                <binding name="NoneSecurity" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
                    <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
                    <security mode="None"/>
                </binding>
            </wsHttpBinding>
        </bindings>

重点是定义binding中不用安全验证的。

下面红色字体的表示终结点binding不用安全验证。

<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoneSecurity"  contract="mccn.Pureview.WCFBusinessService.IPureviewService">

 

客户端配置:

 

><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IPureviewService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                       
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
          <!--http://erpdev.mccn.com.cn:8002/mccn.Pureview.WCFBusinessService.PureviewService.svc?wsdl-->
          <!--address="http://localhost:8732/Design_Time_Addresses/mccn.Pureview.WCFBusinessService/Service1/"-->
          <endpoint address="http://erpdev.mccn.com.cn:8002/mccn.Pureview.WCFBusinessService.PureviewService.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPureviewService"
                contract="ServiceClient.IPureviewService" name="WSHttpBinding_IPureviewService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>

 

<security mode="None" />                     客户端不进行验证设置

出错调试:

服务器端报错,

在事件查看器中查看失败的终结点验证异常消息

  1. 单击“开始”菜单,并选择“运行…”

  2. 键入 eventvwr,然后单击“确定”

  3. 在事件查看器窗口中,单击“应用程序”

  4. 双击“应用程序”窗口中“WebHost”类别下新添加的“System.ServiceModel 4.0.0.0”事件,可以查看不安全的终结点消息。

设置、生成和运行示例

  1. 请确保已经执行了 Windows Communication Foundation 示例的一次性安装过程

  2. 若要生成 C# 或 Visual Basic .NET 版本的解决方案,请按照生成 Windows Communication Foundation 示例中的说明进行操作。

  3. 若要用单机配置或跨计算机配置来运行示例,请按照Running the Windows Communication Foundation Samples中的说明进行操作。

 

posted @ 2012-05-30 11:34  气质优雅的猪  阅读(372)  评论(0编辑  收藏  举报