我已经在wcf服务上创建了(自托管)并使用nettcpip绑定。还有一个名为basicHttpbinding的绑定。我已经为service创建了控制台应用程序。对于消费者也创建了控制台应用程序。这里的内容模式是persession。< / p>
服务:
namespace InstanceMode_PerCall
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Percall : IPercall
{
int number;
public int Increment()
{
number = number + 1;
return number;
}
}
}
接口
namespace InstanceMode_PerCall
{
[ServiceContract]
public interface IPercall
{
[OperationContract]
int Increment();
}
}
config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTCP" receiveTimeout="00:00:03"></binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior" name="InstanceMode_PerCall.Percall">
<endpoint address="InstanceMode_PerCall" binding="netTcpBinding" contract="InstanceMode_PerCall.IPercall" name="netTCP"/>
<endpoint address="InstanceMode_PerCall" binding="basicHttpBinding" contract="InstanceMode_PerCall.IPercall" />
<endpoint address="MEX" binding="mexTcpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080" />
<add baseAddress="net.tcp://localhost:8090"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
消费者:
namespace Consumer_Percall
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Consumer :");
PercallClient client = new PercallClient("netTCP");
for (int i = 0; i <= 20000;i++)
{
int a = client.Increment();
Console.WriteLine(i +" call :" + a+" Time : "+ DateTime.Now);
//a = client.Increment();
//Console.WriteLine("second call :" + a);
//a = client.Increment();
//Console.WriteLine("Third call :" + a);
}
Console.ReadLine();
}
}
}
config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPercall" />
</basicHttpBinding>
<netTcpBinding>
<binding name="netTCP" receiveTimeout=""/>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8090/InstanceMode_PerCall"
binding="netTcpBinding" bindingConfiguration="netTCP" contract="PercallConsumerServiceReference.IPercall"
name="netTCP" />
<endpoint address="http://localhost:8080/InstanceMode_PerCall"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPercall"
contract="PercallConsumerServiceReference.IPercall" name="BasicHttpBinding_IPercall" />
</client>
</system.serviceModel>
</configuration>
对于打印,大约需要10秒。但我提到超时只有3秒。为什么通讯不会停止?在哪里使用receiveTimeout属性clientide或service?
答案 0 :(得分:0)
你误解了财产。表格documentation:
获取或设置连接可以保留的时间间隔 在此之前没有收到应用程序消息的非活动状态 被放弃了。
但是在你的例子中,你不断要求服务增加值,并且在每次请求后重置不活动时间