如何使用基于socket的客户端与WCF(的net.tcp)服务? [英] How to use socket based client with WCF (net.tcp) service?

查看:297
本文介绍了如何使用基于socket的客户端与WCF(的net.tcp)服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了使用通过net.tcp适配器和监听到特定端口的WCF服务。我想连接到使用使用套接字发送数据的端口,并监听响应正常的.NET客户端的服务。
当我尝试将数据发送到这个服务,我得到错误:现有的连接被强行关闭远程主机
。 但是,我能够与其他客户端,它使用了WCF服务的地址/装订/合同服务连接。
有没有一种方法,使我通过使用普通插座的客户端与WCF服务进行通信?

I have developed a WCF service that uses the net.tcp adapter and listens to a specific port. I want to connect to that service using a normal .net client that uses sockets to send data to the port and listens to responses.
When I try to send data to this service, I get the error: "The existing connection was forcibly closed by remote host".
However, i am able to connect with the service by another client which uses the Address/Binding/Contracts of the WCF service.
Is there a way that enables me to communicate with a WCF service by using an ordinary socket based client?

推荐答案

关键的决定是,是否让WCF服务符合套接字客户端或是否使客户端的Socket符合WCF服务。

The key decision is whether or not to make the WCF service conform to the socket client or whether to make the socket client conform to the WCF service.

这将是最简单的尝试,以符合WCF服务,而不是试图实现自定义WCF内的东西,这是不容易的。在你下面的其他资源部分的底部会看到描述是必要的,以便尝试符合WCF服务信息检查链接。

It will be simplest to attempt to conform to the WCF service, rather than trying to implement something custom within WCF, which is never easy. At the bottom of the Other Resources section below you will see a link that describes the message inspection that is necessary in order to attempt to conform to a WCF service.

话虽如此,。NET的插座本身不与WCF沟通。

Having said that, .NET sockets do not natively communicate with WCF.

任何试图这样做将需要的东西方WCF自定义编程。

Any attempt to do so will require custom programming on the WCF side of things.

无论你是使用的TcpClient或原始套接字在.NET连接到并与WCF沟通没关系。任何这样的互操作性必须使用WCF中的自定义逻辑来处理。请注意,是的net.tcp一个自定义的传输协议。它在技术上并不使用TCP以相同的方式,该TcpClient的是

Whether you are using TcpClient or raw sockets in .NET to connect to and communicate with WCF does not matter. Any such interoperability must be handled with custom logic within WCF. Note that Net.Tcp is a custom transport protocol. It is not technically using TCP in the same way that the TcpClient is.

例如,UDP是很常用的Linux世界套接字服务器。 WCF不提供内置的UDP传输。然而,对于一个WCF的UDP样本实现UDP的WCF。不幸的是,该样品没有示连通和从非WCF UPD插座服务器

For example, UDP is very commonly used by socket servers in the Linux world. WCF does not provide a built-in UDP transport. However, there is a UDP sample for WCF that implements UDP for WCF. Unfortunately, that sample does not illustrate communicating to and from a non-WCF UPD socket server.

我有一个突出的问题是相当详细,我解释我的努力获得样品code为一般可测试使用UDP ...

I have an outstanding question that is rather detailed where I explain my effort to get sample code to generically be testable for using UDP...

<一个href="http://stackoverflow.com/questions/484717/error-externally-testing-wcf-udp-custom-transport-channel-sample-from-the-windows">http://stackoverflow.com/questions/484717/error-externally-testing-wcf-udp-custom-transport-channel-sample-from-the-windows

没有人回答我的问题呢。所以,如果你在使这项工作取得成功,我很感兴趣。我的情况,主要是因为一个愿望,WCF服务,能够调出在Linux上运行的UDP套接字服务器,而不必与非WCF编码弄乱我的服务。我不想混的方法。

Nobody has answered my question yet. So, if you succeed in making this work, I am very interested. My case was driven by a desire for the WCF Service to be able to call out to a UDP socket server running on Linux without having to clutter my service with non-WCF coding. I don't want to mix approaches.

其他资源...

  • 选择一个交通运输
    这篇文章指出,WCF TCP传输进行优化 方案,其中的两端 通信使用WCF。

  • Choosing a Transport
    This article states that "The WCF TCP transport is optimized for the scenario where both ends of the communication are using WCF".

<一个href="http://msdn.microsoft.com/en-us/library/ms733769.aspx">http://msdn.microsoft.com/en-us/library/ms733769.aspx

尝试一个非WCF客户端连接到WCF服务 一个使用basicHttpBinding的。
的 开发商最终编写自定义code 经由Web客户端(相对于 TcpClient的)。

<一href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c2d72c2d-c095-4ae1-b8ae-d15f32a4e0be/">http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c2d72c2d-c095-4ae1-b8ae-d15f32a4e0be/

Trying to connect a non-WCF client to a WCF service that uses the BasicHttpBinding.
The developer ends up writing custom code via the WebClient (as opposed to TcpClient).

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c2d72c2d-c095-4ae1-b8ae-d15f32a4e0be/

WCF与原.NET套接字
回答指出,TCP +二进制序列化或UDP +二进制 序列可能是必要的。那里 是一个UDP约束力的样本,因为我 上面提到的。

<一href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c0520111-c1ca-4ffd-a4e0-ac68e86130ee/">http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c0520111-c1ca-4ffd-a4e0-ac68e86130ee/

WCF vs. Raw .NET Sockets
The answer points out that TCP + binary serialization or UDP + binary serialization might be needed. There is a UDP binding sample, as I mentioned above.

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c0520111-c1ca-4ffd-a4e0-ac68e86130ee/

这篇关于如何使用基于socket的客户端与WCF(的net.tcp)服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆