当前位置:网站首页>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");
边栏推荐
- FPGA的虚拟时钟如何使用?
- 快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
- Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
- Transformers pretrainedtokenizer class
- 13 -- 移除无效的括号
- 1279_VMWare Player安装VMWare Tools时VSock安装失败解决
- Auto usage example
- 宝塔面板安装php7.2安装phalcon3.3.2
- Chapter 1 overview of canvas
- C language_ Love and hate between string and pointer
猜你喜欢

Svn actual measurement common operation record operation

Do you still have the opportunity to become a machine learning engineer without professional background?

About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe

OC Extension 检测手机是否安装某个App(源码)

The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain

Backup and restore SQL Server Databases locally

宝塔面板安装php7.2安装phalcon3.3.2

Swift extension chainlayout (UI chain layout) (source code)

Graphmae ---- quick reading of papers

Swift Extension NetworkUtil(网络监听)(源码)
随机推荐
"Adobe international certification" about Adobe Photoshop, creating and modifying brush tutorials?
You get in Anaconda
Vulnhub靶机:BOREDHACKERBLOG: SOCIAL NETWORK
论文笔记: 多标签学习 DM2L
Four models of iPhone 13 series have been exposed, and indeed, they are 13 fragrant!
4-operation list (loop structure)
Vscode topic recommendation
Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
1279_VMWare Player安装VMWare Tools时VSock安装失败解决
12--合并两个有序链表
Unity culling related technologies
Swift extension networkutil (network monitoring) (source code)
MySQL source and target table row count check
etcd备份恢复原理详解及踩坑实录
1-4metaploitable2 introduction
Graphmae - - lecture rapide des documents
复习SGI STL二级空间配置器(内存池) | 笔记自用
Swift extension chainlayout (UI chain layout) (source code)
2022年流动式起重机司机特种作业证考试题库及在线模拟考试
Methods of vector operation and coordinate transformation