简体   繁体   English

WCF客户端和服务器

[英]WCF client and server

I need multiple clients that talk to a WCF service. 我需要多个与WCF服务通信的客户端。 The WCF service also must be able to connect to any one of the clients also. WCF服务还必须能够连接到任何一个客户端。

So - it sounds like the server and the clients need to have both a WCF server and client built into each one. 所以 - 听起来像服务器和客户端需要在每个服务器中都内置WCF服务器和客户端。

Is this correct or is there some way to do this? 这是正确的还是有某种方法可以做到这一点?

I was looking at NetPeerTcpBinding, but that is obsolete. 我在看NetPeerTcpBinding,但这已经过时了。 To be fair I'm not sure if that is a valid solution either. 公平地说,我不确定这是否也是一个有效的解决方案。

Background: 背景:

  • I plan to have a Windows service installed on hundreds of machines in our network with a WCF service and a WCF client built in. 我计划在我们的网络中的数百台机器上安装Windows服务,其中包含WCF服务和内置的WCF客户端。
  • I will have one Windows service installed on a server with a WCF service and a client built in. 我将在具有WCF服务和内置客户端的服务器上安装一个Windows服务。
  • I will have a Windows Forms application 我将有一个Windows窗体应用程序
  • I will have a database 我会有一个数据库

The clients on the network will connect to the service running on the server in order to insert some information on the database. 网络上的客户端将连接到服务器上运行的服务,以便在数据库中插入一些信息。

The user will use the Windows Forms application to connect to the Windows service on the server and this Windows service will connect to the relevant client on the factory floor (to allow remote browsing of files and folders). 用户将使用Windows窗体应用程序连接到服务器上的Windows服务,此Windows服务将连接到工厂车间的相关客户端(以允许远程浏览文件和文件夹)。

Hence I believe the machines on the floor and the server both require a WCF cleint and service built in. 因此,我相信地板上的机器和服务器都需要内置WCF cleint和服务。

The reason people are recommending wsHttpDualBinding is because it is in itself a secure and interoperable binding that is designed for use with duplex service contracts that allows both services and clients to send and receive messages. 人们推荐wsHttpDualBinding的原因是因为它本身就是一个安全且可互操作的绑定,旨在与双工服务契约一起使用,允许服务和客户端发送和接收消息。

The type of communication mentioned 'duplex' has several variations. 提到的“双工”通信类型有几种变化。 Half and Full are the simplest. Half和Full是最简单的。

  • Half Duplex: Works like a walkie-talkie, one person may speak at any given time. 半双工:像对讲机一样工作,一个人可以在任何时间说话。
  • Full Duplex: Like a phone, any person may speak at any given time. 全双工:像手机一样,任何人都可以在任何时间发言。

Each will introduce a benefit and a problem, they also provide ways to build this communication more effectively based upon your needs. 每个都会带来好处和问题,它们还提供了根据您的需求更有效地建立这种沟通的方法。


I'm slightly confused, but I'll attempt to clarify. 我有点困惑,但我会试着澄清一下。

You have an assortment of approaches that may occur here, a Windows Communication Foundation (WCF) Service requires the following: 您可以在此处进行各种方法,Windows Communication Foundation(WCF)服务需要以下内容:

  • Address 地址
  • Binding 捆绑
  • Contract 合同

Those are essentially the "ABC's" for WCF. 这些基本上是WCF的“ABC”。 The creation of those depicts a picture like this: 这些图片的创作描绘了这样的图片:

WCF图

As you can see the Service will contain: 如您所见,服务将包含:

  • Host 主办
  • Service 服务
  • Client 客户

The host houses the service which the client will consume so those service methods perform a desired task. 主机容纳客户端将使用的服务,因此这些服务方法执行期望的任务。 An example representation: 示例表示:

端点

As you see Client-1 is going through the Internet (HTTP, HTTPS, etc.) then will hit the Host, which will have the service perform those tasks. 如您所见, Client-1正在通过Internet(HTTP,HTTPS等),然后将命中主机,这将使服务执行这些任务。

Now Client-n is consuming the service locally, so it is talking over (TCP, etc.) as an example. 现在Client-n正在本地使用该服务,因此它正在谈论(TCP等)作为示例。

The easiest way to remember: One service can be consumed by however many clients require those methods to perform a task. 最容易记住的方法:许多客户端需要这些方法来执行任务,因此可以使用一种服务。 You can create very complex models using a service-oriented architecture (SOA). 您可以使用面向服务的体系结构 (SOA)创建非常复杂的模型。

All WCF is, is a mean to connect your application to a host or centralized location you may not have access to. 所有WCF都是将您的应用程序连接到您可能无法访问的主机或集中位置的意思。

客户端通过服务来托管,访问数据库。

As you can see in the above image, the Client communicates through a Service to the Host. 如上图所示,客户端通过服务与主机进行通信。 Which performs a series of task. 其中执行一系列任务。 WCF will talk over an array of protocols. WCF将讨论一系列协议。 Hopefully this will provide a better understanding of how WCF is structured. 希望这将更好地理解WCF的结构。

There are a lot of tutorials and even post to get you started. 有很多教程甚至帖子可以帮助您入门。 Some excellent books such as "WCF Step by Step" . 一些优秀的书籍,如“WCF Step by Step”


Essentially your looking for an asynchronous full duplex connection, or a synchronous full duplex service. 基本上您正在寻找异步全双工连接或同步全双工服务。 As mentioned above, your task in essence is the point of a Service. 如上所述,您的任务本质上是服务的重点。

The question: How does this work best? 问题:这怎么效果最好?

It will boil down to your design. 它将归结为您的设计。 There are limitations and structures that you will need to adhere to to truly optimize it for your goal. 您需要遵守一些限制和结构,以便为您的目标真正优化它。

Such obstacles may be: 这些障碍可能是:

  1. Server Load 服务器负载
  2. Communication Path 沟通路径
  3. Security 安全
  4. Multiple Clients Altering UI / Same Data 多个客户端更改UI /相同数据
  5. Etc. 等等。

The list continues and continues. 该列表继续并继续。 I'd really look up tutorials or a few books on WCF. 我真的会在WCF上查阅教程或一些书。 Here are a few: 以下是一些:

They will help you work with the service structure to adhere to your desired goal. 它们将帮助您使用服务结构以符合您的预期目标。


Remember the "ABCs" for the most success with WCF. 记住使用WCF取得最大成功的“ABCs”。

Use wsDualHttpBinding if you want your service communicate with your clients. 如果您希望您的服务与您的客户进行通信,请使用wsDualHttpBinding。

Read WS Dual HTTP . 读取WS双HTTP

You might want to try out creating a WCF service using netTcpBinding . 您可能希望尝试使用netTcpBinding创建WCF服务。 It will work for your requirements. 它将适合您的要求。 You can use the article How to: Use netTcpBinding with Windows Authentication and Transport Security in WCF Calling from Windows Forms as a start: 您可以使用以下文章: 如何:在WCF中使用Windows身份验证和传输安全性的netTcpBinding从Windows窗体作为开始:

Also, there are many examples included within the WCF Samples package which you can use. 此外,您可以使用WCF Samples包中包含的许多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM