Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of transferring from Winform to WCF

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "case analysis from Winform to WCF". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Xiaosheng was born in Winform. Recently, I always wanted to transfer to BS. I thought WCF was a good entry point for me, so I read some WCF materials. I personally felt that it was easy to learn a technology, but the difficult part was how to integrate this technology with my own knowledge. My motivation for learning WCF was relatively simple. I first learned WCF, encapsulated the business logic of my current Winform system in WCF, and formed the structure of Winform + WCF. And then proceed with the BS system.

That is,

Step 1.Winform + local business logic

Step 2.Winform + WCF

Step 3.Winform + Browser + WCF

Step 4.Browser + WCF

But at the beginning of contact with WCF, I feel very unaccustomed, the reason is very simple.

But if I have a class.

Class A {A (String id); void op () {}; B getB () {}; String p1 {get;set;}} class B {string id; void op2 ();}

Here, I can not directly convert An into a service, the reason is very simple, if An as a service, then B can only be implemented as the data of a service.

The operation of B cannot be realized by op2.

At first, I didn't understand it, and I felt that this design was tantamount to conflict. Because, even if An and B are used as a service, the management is also very chaotic.

On the other hand, the online tutorials on WCF are all about implementation.

There is no introduction to design.

I thought for a moment, hehe, people don't laugh, this is really difficult for me, I have to figure out these things.

I feel that in the implementation of a real service, it is equivalent to separating the operation and data of a class to reduce granularity and coupling, which does not conflict with the idea of OO.

In WCF, the logic for A _ meme B should be treated as follows.

First of all, for A, An is divided into two classes: ServiceA and DataContractA, where ServiceA is the service contract of WCF and DataContractA is the data contract.

Code class ServiceA {DataContractA Op (DataContractA); / corresponds to A.op () DataContractA GetDataContractA (string id); / / corresponds to the constructor DataContractB GetB (DataContrac A) of A; / / corresponds to A.getB ()} class DataContractA {String p1 {get;set;} / / corresponds to attribute p1} of A.

Do the same for Class B.

Class ServiceB {DataContractB Op2 (DataContractB b); / / corresponds to B.op2} class DataContractB {string id {get;set;} / / corresponds to b.id}

In this way, the original logic makes a normal transition to WCF services.

This is the end of the content of "case Analysis from Winform to WCF". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report