WCF 安全性 之 None

案例下載html

http://download.csdn.net/detail/woxpp/4113172tcp

服務端配置代碼ide

  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary.ServiceTcp">
        <endpoint address="net.tcp://localhost:8731/WcfServiceLibrary"
          binding="netTcpBinding" bindingConfiguration="testnetTcpBinding"
          contract="WcfServiceLibrary.IServiceTcp">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/WcfServiceLibrary" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 爲避免泄漏元數據信息,
          請在部署前將如下值設置爲 false 並刪除上面的元數據終結點  -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- 要接收故障異常詳細信息以進行調試,
          請將如下值設置爲 true。在部署前設置爲 false 
            以免泄漏異常信息-->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="testnetTcpBinding">
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

客戶端調用代碼  經過代理 代理生成 參見spa

http://www.cnblogs.com/woxpp/p/6232298.html.net

客戶端調用代碼 代理

    private void btnTest_Click(object sender, EventArgs e)
        {
            NetTcpBinding netTcp = new NetTcpBinding();
            ChannelFactory<IServiceTcp> ftc = new ChannelFactory<IServiceTcp>();
            netTcp.Security.Mode = SecurityMode.None;
            IServiceTcp proxy = ChannelFactory<IServiceTcp>.CreateChannel(netTcp, new EndpointAddress("net.tcp://127.0.0.1:8731/WcfServiceLibrary"));
            txtMessage.Text = proxy.GetDataUsingDataContract(new WcfServiceLibrary.CompositeType() { StringValue = "sssss" }).StringValue;

        }
相關文章
相關標籤/搜索