案例下載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.IService1"> <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="Message"> <transport clientCredentialType="None" protectionLevel="None"></transport> <message clientCredentialType="Windows"/> </security> </binding> </netTcpBinding> </bindings> </system.serviceModel>
客戶端調用代碼 經過代理類spa
http://www.cnblogs.com/woxpp/p/6232298.html.net
客戶端代碼代理
//獲取域名 String hostName = Dns.GetHostName(); IPHostEntry ipH = new IPHostEntry(); ipH = Dns.Resolve(hostName); NetTcpBinding netTcp = new NetTcpBinding(); netTcp.Security.Mode = SecurityMode.Message; netTcp.Security.Transport.ProtectionLevel = ProtectionLevel.None; netTcp.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; netTcp.Security.Message.ClientCredentialType = MessageCredentialType.Windows; ChannelFactory<IService1> factory = new ChannelFactory<IService1>(netTcp); factory.Credentials.Windows.ClientCredential.UserName = "panpan.xu"; factory.Credentials.Windows.ClientCredential.Password = "123.xpp"; factory.Credentials.Windows.ClientCredential.Domain = "panpanxu-PC"; IService1 proxy = factory.CreateChannel(new EndpointAddress("net.tcp://localhost:8731/WcfServiceLibrary")); txtMessage.Text = proxy.GetDataUsingDataContract(new WcfServiceLibrary.CompositeType() { StringValue = "sssss" }).StringValue;