如何动态创建 WCF 端点与配置文件中定义的静态端点?

发布于 2024-10-10 02:56:18 字数 1086 浏览 0 评论 0原文

我目前拥有的是一个多方、多聊天的应用程序; P2P,它使用较旧的 .NET v2.0 方法。仅限内联网。

我所追求的是如何动态创建 WCF 端点与配置文件中定义的静态端点;剩下的我可以做。我将使用通用消息与静态(预定义)消息,因此这允许动态消息传递。我将使用 WCF 中的 HTTP 传输来发送和接收“普通旧 XML”(POX) 消息;也就是说,消息仅由 XML 有效负载组成,没有任何封闭的 SOAP 信封。

或者我应该假设每个工作站都需要相同的基本端口,并且仅将其用作唯一端口,并且不存在网络冲突(例如,2 个来宾工作站同时与同一主机工作站通信)?

我想将其移至 WCF,但端点问题已经困扰了我;例如,似乎无法弄清楚。

历史: 我当前的聊天应用程序使用旧的 .NET v2.0 方法。我有大约 50 个工作站,每个工作站都分配有一个静态端口,例如 50100、50200、50300 等。这允许在 50100 ~ 50199 范围内最多有 99 个端口;端口 50100 是“基本”端口,端口 50101 ~ 50199 是“主机”端口,最多允许同时进行 99 个“主机”聊天会话。工作站可以在端口 50101 到 50105 上托管多个聊天会话。它们还可以“加入”(成为访客)其他工作站端口范围内的聊天。

每个工作站都在其基本端口上“侦听”,例如 50100。当聊天请求进入其基本端口时,发出请求的“服务器”提供动态创建的端口以作为访客“加入”聊天请求。在此示例中,工作站 A(基本端口 50100)收到工作站 B 的邀请,在端口 50235 上加入(50200 是工作站 B 用于传入聊天请求的“基本”端口)。 顺便说一句:我使用网络服务来跟踪用户何时在线或离线。聊天应用程序在打开/退出时向 Web 服务注册/取消注册。

当前的 WFC 模型 对于 WCF,我不知道如何将上面的模型“移植”(无双关语)到 WCF 模型中。配置文件显示所有工作站的单个端口。作为主机和访客,同一端口上是否可以发生多个聊天?我认为不会。

简而言之,我如何纯粹用 C# 代码动态创建端点,没有静态配置文件端点,或者可以吗?我似乎找不到任何例子。

也就是说,基础工作站端口(端点)将“监听”聊天请求;它将创建一个端点以将聊天请求发送到另一个工作站的基本端口(端点),并在受邀聊天时创建一个端点。

谢谢,

加里·N

What I currently have is is a multi-party, multi-chat app; P2P at that, which uses the older .NET v2.0 method. Intranet only.

What I'm after is how to dynamically create WCF endpoints versus a static endpoint defined in the config file; I can do the rest. I'll be using a generic message vs. static (predefined), so this allows for dynamic message passing. I'll use the HTTP transport in WCF to send and receive “plain old XML” (POX) messages; that is, messages that consist solely of XML payloads without any enclosing SOAP envelope.

OR should I just assume that the same base port is all that is needed for every workstation and merely use that as the sole port, and that there's no network clash conflict (e.g. 2 guest workstations simultaneously communicating with the same host workstation)?

I'd like to move it to WCF, but the endpoint thing has got me; e.g. can't seem to figure it out.

History:
My current chat app uses the older .NET v2.0 method. I have about 50 workstations and each is assigned a static port, e.g. 50100, 50200, 50300, etc. This allows for up to 99 ports in the range of 50100 ~ 50199; port 50100 is the 'base' port, and ports 50101 ~ 50199 are 'host' ports which allows up to 99 'host' chat sessions simultaneously. The workstation can host several chat sessions on, say, ports 50101 thru 50105. They can also 'join' (be a guest) on chats within the port range of the other workstations.

Each workstation is 'listening' on their base port, e.g. 50100. When a chat request comes in on their base port, the requesting "server" provides the dynamically created port to 'join' the chat request as a guest. In this example, workstation A (base port 50100) gets an invite from workstation B to join on port 50235 (50200 is Workstation B's 'base' port for incoming chat requests).
BTW: I use a web service to track when users are online or not. The chat app registers/unregisters with the web service when opening/quitting.

Current WFC model
With WCF, I don't see how this model above can be 'ported' (no pun intended) into the WCF model. The config file shows a single port for all workstations. Can multiple chats occur on the same port, both as host and guest? I would think not.

The short of it being, how could I dynamically create endpoints purely in C# code, no static config file endpoint, or can I? I can't seem to find any examples.

That is, the base workstation port (endpoint) will 'listen' for chat requests; it will create an endpoint to send a chat request to another workstation's base port (endpoint), and will create an endpoint when invited to a chat.

Thx,

GaryN

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光①夏 2024-10-17 02:56:18

You can define a service endpoint in code instead of in the configuration file, see http://msdn.microsoft.com/en-us/library/ms731080.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文