Web服务和TCP客户端线程之间的通信 [英] communicating between a web service and TCP client thread

查看:117
本文介绍了Web服务和TCP客户端线程之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个RESTful Web服务,该服务可以与TCP/IP客户端来回传递信息.我想我可以通过某种事件处理程序(使用共享资源)来做到这一点.我遇到的麻烦是如何从Web服务中创建TCP客户端线程,或者如何在其他位置创建TCP客户端线程,如何维护两者之间的共享资源?

基本上,我正在寻找的是这种程序流:TCP/IP客户端启动与服务器的连接并等待. Web服务接收一个HTTP请求,然后将其传递给TCP客户端.客户端处理该请求,然后将响应传递到Web服务,该Web服务会将其作为对原始请求的响应发送回去.

I am trying to create a RESTful web service that can pass information back and forth with a TCP/IP client. I figured I would do this by some sort of event handler, with shared resources. What I am having trouble with is grasping how to create the TCP client thread from within the web service or if it''s created elsewhere, how do I maintain those shared resources between the two?

Basically, what I''m looking for is this kind of program flow: The TCP/IP client starts the connection to the server and waits. The web service recieves an HTTP request, which it then passes to the TCP client. The client processes the request, and then passes a response to the web service, which would send it back out as a response to the original request.

any information or tips is greatly appreciated.

推荐答案

可以通过在WCF服务中将端点添加为以下方式来实现:

Itz possible by adding an endpoint in WCF service as:

<endpoint address="net.tcp://localhost:8008/MyService"

  binding="netTcpBinding"

  contract="MyServer.MyService.IService" />



现在,TCP客户端可以使用此端点来实现与服务的TCP连接.



Now, TCP client can consume this end point for TCP connectivity with service.


这篇关于Web服务和TCP客户端线程之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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