Home > Net >  WCF transmission to TransferMode. Streamed host. Open the problem of failure
WCF transmission to TransferMode. Streamed host. Open the problem of failure

Time:11-07

The HTML code is as follows, consult everybody, why tcpBinding. TransferMode=TransferMode. Streamed; Don't start, the pop-up dialog, tips are as follows:
"Protocol requires session, but the binding NetTcpBinding or does not support it because of configuration is not correct, unable to support it,

IsServerRun=true;
//get the native IP
String IP=GetIP ();
String tcpaddress=the string. Format (" net. TCP://{0}, {1}/", IP, ServerPort);
//set netTCP agreement
NetTcpBinding tcpBinding=new NetTcpBinding ();
TcpBinding. MaxBufferPoolSize=2147483647;
TcpBinding. MaxReceivedMessageSize=2147483647;
TcpBinding. MaxBufferSize=2147483647;

TcpBinding. ReceiveTimeout=TimeSpan. MaxValue.
TcpBinding. SendTimeout=TimeSpan. MaxValue.
//to provide safe transmission
TcpBinding. Security. Mode=SecurityMode. None;
TcpBinding. TransferMode=TransferMode. Buffered;
//will need to provide certificate
TcpBinding. Security. Transport. ClientCredentialType=TcpClientCredentialType. Certificate;
//add multiple service endpoints
//use specified in the agreement, binding and endpoint address in the add service endpoint to the hosted service
//netTcp protocol endpoints
//define the service host
ServiceHost host=new ServiceHost (typeof (MainServer), the new Uri (tcpaddress));//typeof for class type
Host. AddServiceEndpoint (typeof (IMainServer), tcpBinding, tcpaddress);//typeof for interface type

# region to add behavior
////metadata release behavior
ServiceMetadataBehavior behaviors=new ServiceMetadataBehavior ();
Behaviors. HttpGetEnabled=false;
//set to the Host
The host. The Description. Behaviors. The Add (Behaviors);
# endregion
//set the data exchange type
Host. AddServiceEndpoint (typeof (IMetadataExchange), MetadataExchangeBindings. CreateMexTcpBinding (), "tex-mex");
//start the service
The host. The Open ();
SetToolStripStatusLabelMessage (enclosing toolStripStatusLabel1, string Format (" service started successfully, running... {0} ", tcpaddress), Color, Green);
}
The catch (Exception ex)
{
SetToolStripStatusLabelMessage (enclosing toolStripStatusLabel1, service failure "started the Color, Red);
MessageBox. Show (ex. The Message, "service start failure");
Environment. The Exit (0);
}
  •  Tags:  
  • C#
  • Related