如何将WCF中基于nettcp协议的通讯方法改写为一个长尾词的?

2026-04-01 11:521阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计626个文字,预计阅读时间需要3分钟。

如何将WCF中基于nettcp协议的通讯方法改写为一个长尾词的?

在WCF中使用Net.Tcp协议进行通讯,首先需要创建一个公共类来打开WCF服务。以下是一个简化的示例:

csharpusing System.ServiceModel;

public class MyWcfService{ [ServiceContract] public interface IMyService { [OperationContract] string ABC(); }

public class MyService : IMyService { public string ABC() { // 实现方法 return Hello, WCF!; } }

public static void Main() { ServiceHost host=new ServiceHost(typeof(MyService));

// 配置Service host.Description.Services[0].Name=MyService; host.BaseAddresses.Add(new Uri(http://localhost:8000/MyService));

// 配置binding NetTcpBinding binding=new NetTcpBinding(); host.AddServiceEndpoint(typeof(IMyService), binding, );

// 配置behaviors host.Open(); Console.WriteLine(Service is running...); Console.ReadLine(); host.Close(); }}

注意:- 在配置文件中,确保正确设置`Service`, `binding`, 和 `behaviors`。- 在`Service`中配置`endpoint`,例如`abc`。- 在`binding`中配置`tcp`通信协议。

示例中省略了详细配置,但确保按照实际需求调整。

快速阅读

如何在wcf中用net tcp协议进行通讯,一个打开Wcf的公共类。比较好好,可以记下来。 配置文件中注意配置 Service,binding,behaviors. Service中配置endpoint 指明abc ,binding中配置tcp通讯的要关参数,behaivor中配置localhost:12345/User" binding="netTcpBinding" contract="hcbServiceB.IUser"> <identity> <dns value="localhost"/> </identity> </endpoint> </service> </services> <bindings> <netTcpBinding> <binding name="netTcpBindingConfig" closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="100" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="100" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647 " maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:30:00" enabled="false" /> <security mode="Transport"> <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> </security> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="userBehavior"> <serviceMetadata localhost:8081/User" /> <serviceDebug includeExceptionDetailInFaults="True" /> <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>

4.启动服务

控制台中启动服务

static void Main(string[] args) { Console.WriteLine("初始化..."); Console.WriteLine("服务运行期间,请不要关闭窗口。"); Console.Title = "wcf net tcp测试 "; var cancelTokenSouce = new CancellationTokenSource(); ServiceHostManager<User>.StartNew(cancelTokenSouce); while (true) { if (Console.ReadKey().Key == ConsoleKey.Escape) { Console.WriteLine(); cancelTokenSouce.Cancel(); break; } } }

5wcftesttoos软件测试

软件路径位于,可以根据自己安装vs的目录去找。
D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE

测试


参考:

WCF绑定netTcpBinding寄宿到控制台应用程序:www.jb51.net/article/165257.htm

总结

如何将WCF中基于nettcp协议的通讯方法改写为一个长尾词的?

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对易盾网络的支持。

标签:方法

本文共计626个文字,预计阅读时间需要3分钟。

如何将WCF中基于nettcp协议的通讯方法改写为一个长尾词的?

在WCF中使用Net.Tcp协议进行通讯,首先需要创建一个公共类来打开WCF服务。以下是一个简化的示例:

csharpusing System.ServiceModel;

public class MyWcfService{ [ServiceContract] public interface IMyService { [OperationContract] string ABC(); }

public class MyService : IMyService { public string ABC() { // 实现方法 return Hello, WCF!; } }

public static void Main() { ServiceHost host=new ServiceHost(typeof(MyService));

// 配置Service host.Description.Services[0].Name=MyService; host.BaseAddresses.Add(new Uri(http://localhost:8000/MyService));

// 配置binding NetTcpBinding binding=new NetTcpBinding(); host.AddServiceEndpoint(typeof(IMyService), binding, );

// 配置behaviors host.Open(); Console.WriteLine(Service is running...); Console.ReadLine(); host.Close(); }}

注意:- 在配置文件中,确保正确设置`Service`, `binding`, 和 `behaviors`。- 在`Service`中配置`endpoint`,例如`abc`。- 在`binding`中配置`tcp`通信协议。

示例中省略了详细配置,但确保按照实际需求调整。

快速阅读

如何在wcf中用net tcp协议进行通讯,一个打开Wcf的公共类。比较好好,可以记下来。 配置文件中注意配置 Service,binding,behaviors. Service中配置endpoint 指明abc ,binding中配置tcp通讯的要关参数,behaivor中配置localhost:12345/User" binding="netTcpBinding" contract="hcbServiceB.IUser"> <identity> <dns value="localhost"/> </identity> </endpoint> </service> </services> <bindings> <netTcpBinding> <binding name="netTcpBindingConfig" closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="100" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="100" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647 " maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:30:00" enabled="false" /> <security mode="Transport"> <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> </security> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="userBehavior"> <serviceMetadata localhost:8081/User" /> <serviceDebug includeExceptionDetailInFaults="True" /> <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>

4.启动服务

控制台中启动服务

static void Main(string[] args) { Console.WriteLine("初始化..."); Console.WriteLine("服务运行期间,请不要关闭窗口。"); Console.Title = "wcf net tcp测试 "; var cancelTokenSouce = new CancellationTokenSource(); ServiceHostManager<User>.StartNew(cancelTokenSouce); while (true) { if (Console.ReadKey().Key == ConsoleKey.Escape) { Console.WriteLine(); cancelTokenSouce.Cancel(); break; } } }

5wcftesttoos软件测试

软件路径位于,可以根据自己安装vs的目录去找。
D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE

测试


参考:

WCF绑定netTcpBinding寄宿到控制台应用程序:www.jb51.net/article/165257.htm

总结

如何将WCF中基于nettcp协议的通讯方法改写为一个长尾词的?

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对易盾网络的支持。

标签:方法