当前位置:网站首页>WCF TCP protocol transmission
WCF TCP protocol transmission
2022-06-24 08:16:00 【Changchun procedural ape】
1、 Server side :
using com.jbossjf.common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
// Author Wei :jbossjf
namespace com.jbossjf.core
{
public class WcfService
{
private static ServiceHost basefileHost = null;
public int StartWcfService()
{
try
{
if (basefileHost == null)
{
// Use code binding
Uri tcpa = new Uri("net.tcp://" + CommonHelp.ip + ":8866/BasefileService");
basefileHost = new ServiceHost(typeof(com.jbossjf.core.BasefileService), tcpa);
ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();
NetTcpBinding tcpb = new NetTcpBinding()
{
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{
MaxStringContentLength = 2147483647
},
Security = new NetTcpSecurity()
{
Mode = SecurityMode.None
},
ReceiveTimeout = new TimeSpan(0,1,30)
,
SendTimeout = new TimeSpan(0,1,30)
,
MaxBufferSize = 65536
,
MaxBufferPoolSize = 524288
,
MaxReceivedMessageSize = 65536
//OpenTimeout = new TimeSpan(0,0,5)
//,
//CloseTimeout = new TimeSpan(0,1,0)
};
basefileHost.Description.Behaviors.Add(mBehave);
basefileHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
basefileHost.AddServiceEndpoint(typeof(com.jbossjf.core.IBasefileService), tcpb, tcpa);
// NetTcpBinding binding = new NetTcpBinding()
basefileHost.Open();
return 1;
}
}
catch(Exception ex){
CommonHelp.WriteLog(ex.Message);
}
return 0;
}
public int CloseWcfService()
{
try
{
if (basefileHost != null)
{
basefileHost.Close();
return 1;
}
}
catch { }
return 0;
}
// using (ServiceReferenceDemo.Service1Client sc = new ServiceReferenceDemo.Service1Client())
//{
// sc.Open();
// MessageBox.Show(sc.GetData(10));
// sc.Close();
//}
}
}
2、 client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace com.jbossjf.core.WCF
{
public class WcfHelp
{
public static com.jbossjf.core.BasefileServiceReference.BasefileServiceClient _BasefileServiceReference = null;
public com.jbossjf.core.BasefileServiceReference.BasefileServiceClient GetBasefileServiceClient()
{
try
{
if (_BasefileServiceReference == null)
{
_BasefileServiceReference = new core.BasefileServiceReference.BasefileServiceClient();
// if (!_BasefileServiceReference.State.ToString().Equals("Created"))
_BasefileServiceReference.Open();
}
if (_BasefileServiceReference.State.ToString().Equals("Faulted"))
{
try
{
_BasefileServiceReference = null;
_BasefileServiceReference = new core.BasefileServiceReference.BasefileServiceClient();
_BasefileServiceReference.Open();
}
catch { }
//_BasefileServiceReference = new core.BasefileServiceReference.BasefileServiceClient();
}
}
catch { }
return _BasefileServiceReference;
}
}
}
DataTable dt = _WcfHelp.GetBasefileServiceClient().FindFermentationALL("jbossjf");
边栏推荐
- Introduction to software engineering - Chapter 2 - feasibility study
- Solve the problem of notebook keyboard disabling failure
- 【毕业季】你好陌生人,这是一封粉色信笺
- Pipeline concept of graphic technology
- Transformers pretrainedtokenizer class
- 1279_ Vsock installation failure resolution when VMware player installs VMware Tools
- Leetcode exercise - jumping game, combination summation
- MySQL source and target table row count check
- 宝塔面板安装php7.2安装phalcon3.3.2
- FPGA的虚拟时钟如何使用?
猜你喜欢
随机推荐
Simple summary of lighting usage
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
GraphMAE----论文快速阅读
auto使用示例
How to use the virtual clock of FPGA?
Solution of electric education system for intelligent supervision station
模型效果优化,试一下多种交叉验证的方法(系统实操)
Oracle advanced SQL qualified query
LINQ 查询(2)
Qopengl display point cloud file
Industrial computer anti cracking
os.path.join()使用过程中遇到的坑
Installation and use of selenium IDE
FPGA的虚拟时钟如何使用?
对于flex:1的详细解释,flex:1
Backup and restore SQL Server Databases locally
SQL intra statement operation
一文理解同步FIFO
自动化测试的未来趋势
Online education fades