当前位置:网站首页>My practice of SOA architecture project based on WCF
My practice of SOA architecture project based on WCF
2022-06-13 02:49:00 【afeng124】
I'm not very talented , In the current project, I am both a programmer and the head of the architecture design team . In the use of WCF Before the technology, I have seen countless claims WCF Practical blog , None of them is what I want . But I've learned something . In this thanked , Thank you very much for your kind sharing and hard work . I haven't blogged for a long time , Recent research WCF I have some tips to share with you . Please also skip , I hope I won't waste your expressions . Here are some pictures , We will talk about the process later .
- Solution screenshot




Problems encountered in the architecture process and solutions .
1、 Do you want to use dto object , Do you want to establish DTO layer ?
The solution is to skillfully combine entity objects with dto Object to merge , This eliminates the conversion process . Feeling ok .
Samples are as follows :
namespace RTLS.Entities
{
[Serializable, DataContract(IsReference = true)]
[KnownType(typeof(SysRolefunc))]
public class SysRole
{
[DataMember]
public virtual int Roleid { get; set; }
[DataMember]
public virtual string Rolename { get; set; }
[DataMember]
public virtual bool Active { get; set; }
[DataMember]
public virtual string Desc { get; set; }
[DataMember]
public virtual DateTime? Timestamp { get; set; }
[DataMember]
public virtual string Remark { get; set; }
private IList<SysRolefunc> list;
// One-to-many relation : role (Role) Have one or more role functions (SysRolefunc)
[DataMember]
public virtual IList<SysRolefunc> RoleFuncs
{
get
{
if (list == null)
{
list = new List<SysRolefunc>();
}
return list;
}
set
{
list = value;
}
}
}
}
using System;
using System.ServiceModel;
namespace RTLS.IServices
{
[ServiceContract]
public interface ISysRoleService
{
[OperationContract]
bool AddSysRole(RTLS.Entities.SysRole role);
[OperationContract]
bool DeleteSysRole(RTLS.Entities.SysRole role);
[OperationContract]
System.Collections.Generic.IList<RTLS.Entities.SysRole> GetAll(bool isActive);
[OperationContract]
System.Collections.Generic.IList<RTLS.Entities.SysRole> GetPageResults(int curPageNo, int limit,
string name, bool isActive,
ref int totalCount);
[OperationContract]
System.Collections.Generic.IList<RTLS.Entities.SysRole> GetRoleByUserId(int userID);
[OperationContract]
bool ModifySysRole(RTLS.Entities.SysRole role);
}
}
namespace RTLS.Services
{
/// <summary>
/// System role service class
/// </summary>
public class SysRoleService : ISysRoleService
{
private SysRoleBiz biz = new SysRoleBiz();
public bool AddSysRole(Entities.SysRole role)
{
var result = biz.AddSysRole(role);
return result.Success();
}
public bool DeleteSysRole(Entities.SysRole role)
{
return biz.DeleteSysRole(role);
}
public IList<Entities.SysRole> GetAll(bool isActive)
{
return biz.GetAll(isActive);
}
public IList<Entities.SysRole> GetPageResults(int curPageNo, int limit, string name, bool isActive, ref int totalCount)
{
return biz.GetPageResults(curPageNo,limit,name,isActive,ref totalCount);
}
public IList<Entities.SysRole> GetRoleByUserId(int userID)
{
return biz.GetRoleByUserId(userID);
}
public bool ModifySysRole(Entities.SysRole role)
{
return biz.ModifySysRole(role);
}
}
}
Although it is not recommended to use this way , But the construction period is limited . Not used Linq, So if it is dto-->entity,entity-->entity It's going to be a dead man . For this reason, I have planned to give up using WCF, Let the client directly reference BLL and Model layer . Later, it was found that the merger could continue , That's it . Right or wrong, for the time being .
2、 How to debug and set WCF Parameters ?
Of course, it was groping , Fall down , Fall down ... Get up , Come again ! Last few pictures :




<service behaviorConfiguration="RTLS.Services.ServiceBehavior"
name="RTLS.Services.SystemFunctionService">
<endpoint address="net.tcp://192.168.1.123:9998/RTLS_SysFun_Svr" binding="netTcpBinding" bindingConfiguration="myNetTcpBinding"
name="net" contract="RTLS.IServices.ISystemFunctionService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.1.123:9998/RTLS_SysFun_Svr" />
</baseAddresses>
</host>
</service>
</services>
3. One Winnt How about the service host Multiple wcf service ?
protected override void OnStart(string[] args)
{
if (serviceHostes.Count > 0) serviceHostes.Clear();
var configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
ServiceModelSectionGroup serviceModelSectionGroup = (ServiceModelSectionGroup)configuration.GetSectionGroup("system.serviceModel");
// Start each service
foreach (ServiceElement serviceElement in serviceModelSectionGroup.Services.Services)
{
var wcfServiceType = Assembly.Load("RTLS.Services").GetType(serviceElement.Name);
var serviceHost = new ServiceHost(wcfServiceType);
serviceHostes.Add(serviceHost);
serviceHost.Opened += delegate
{
LogManager.WriteLog("Log", string.Format("{0} Start listening Uri by :{1}",
serviceElement.Name, serviceElement.Endpoints[0].Address.ToString()));
};
serviceHost.Open();
}
}
This method is seen in brother Jiri's general permission component , I would like to express my heartfelt thanks to brother Jiri ! I hope you will respect those who are down-to-earth in technology , I'm not trying to advertise with brother Jiri . Be grateful ! You know how to do it , You despise me can , I don't envy you , I don't have to fuck you .
4、 How to use generic factory classes to simplify and refactor code ?
This is being tried , After all, I finished it first .
5、 Use winnt Service installation 、 Is it easy to publish ? Is it easy to use? ?



/// <summary>
/// The main entry point for the application .
/// </summary>
static void Main(string[] args)
{
if (args.Length > 0)
{
AssemblyInstaller myAssemblyInstaller;
myAssemblyInstaller = new AssemblyInstaller();
myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = System.AppDomain.CurrentDomain.BaseDirectory + "\\" + System.AppDomain.CurrentDomain.FriendlyName;
System.Collections.Hashtable mySavedState = new System.Collections.Hashtable();
switch (args[0].ToLower())
{
case "-i":
myAssemblyInstaller.Install(mySavedState);
myAssemblyInstaller.Commit(mySavedState);
myAssemblyInstaller.Dispose();
return;
case "-u":
myAssemblyInstaller.CommandLine = new string[1] { "/u" };
myAssemblyInstaller.Uninstall(null);
myAssemblyInstaller.Dispose();
return;
default:
System.Console.WriteLine("------ Parameter description ------");
System.Console.WriteLine("- i Installation services !");
System.Console.WriteLine("- u Uninstall service !");
System.Console.ReadKey();
return;
}
}
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new RtlsHostSvr()
};
ServiceBase.Run(ServicesToRun);
Want to know how to debug a service program like a console program ? Put the service OnStart The method is marked public new . The default is protected override. Then remove those comments as follows , And note the above The code of ok 了 .
//var sHostSvr = new RtlsHostSvr();
//sHostSvr.OnStart(null);
//System.Threading.Thread.Sleep(10000);
//sHostSvr.OnStop();
}
边栏推荐
- Matlab: obtain the figure edge contour and divide the figure n equally
- [life science] DNA extraction of basic biological experiments
- String: number of substring palindromes
- js多种判断写法
- too old resource version,Code:410
- 01 initial knowledge of wechat applet
- vant实现移动端的适配
- Ijkplayer source code ---packetqueue
- [data analysis and visualization] key points of data drawing 9- color selection
- [reading papers] deep learning face representation from predicting 10000 classes. deepID
猜你喜欢

The latest Matlab r2020 B ultrasonic detailed installation tutorial (with complete installation files)
![Leetcode 926. Flip string to monotonically increasing [prefix and]](/img/ca/d23c1927bc32393cf023c748e4b449.png)
Leetcode 926. Flip string to monotonically increasing [prefix and]

A real-time target detection model Yolo

How to destroy a fragment- How to destroy Fragment?

OneNote使用指南(一)
![[life science] DNA extraction of basic biological experiments](/img/84/c1968c2c08feab44b14a529420eea9.jpg)
[life science] DNA extraction of basic biological experiments
![[reading papers] deepface: closing the gap to human level performance in face verification. Deep learning starts with the face](/img/e4/a25716ae7aa8bdea64eb9314ca2cc7.jpg)
[reading papers] deepface: closing the gap to human level performance in face verification. Deep learning starts with the face
![[reading papers] dcgan, the combination of generating countermeasure network and deep convolution](/img/31/8c225627177169f1a3d6c48fd7e97e.jpg)
[reading papers] dcgan, the combination of generating countermeasure network and deep convolution

Node uses post to request req Pit with empty body

Radio design and implementation in IVI system
随机推荐
Rough understanding of wechat cloud development
数字IC设计——FIFO的设计
[reading papers] comparison of deeplobv1-v3 series, brief review
Linked list: orderly circular linked list
02 optimize the default structure of wechat developer tools
Linked list: delete the penultimate node of the linked list
冲刺强基计划数学物理专题一
Linked list: palindrome linked list
OneNote使用指南(一)
Ijkplayer source code - setting option 2
Principle and steps of principal component analysis (PCA)
[reading papers] deep learning face representation by joint identification verification, deep learning applied to optimization problems, deepid2
Linked lists: rearranging linked lists
Data warehouse notes | 5 factors that need attention for customer dimension modeling
Prometheus node_exporter安装并注册为服务
[common tools] pyautogui tutorial
IOS development interview knowledge sorting - OC Foundation (II)
Example 4 linear filtering and built-in filtering
Mp4 playback
[reading papers] visual convolution zfnet