WebService向winform发送字符串消息 WebService和winform在同一电脑上,如何实现WebService向winform发送字符串数据?我试了SendMessage,Web不能正确获取WinForm窗口句柄(FindWindow)。什么方式最简便、快捷?最好有示例代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道用Socket可不可以,我不太懂 这个不是反过来了么?成了winform向webservice发送消息了。这个用socket通信最简单了,以后分开部署只要联网也没问题的。贴部分socket通信的代码给你,byte[] bytes = new Byte[1024]; IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1003); Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { listener.Bind(localEndPoint); listener.Listen(10); while (true) { Console.WriteLine("Waiting for a connection"); Socket handler = listener.Accept(); data = null; while (true) { bytes = new byte[1024]; int bytesRec = handler.Receive(bytes); data += Encoding.ASCII.GetString(bytes, 0, bytesRec); if (data.IndexOf("<EOF>") > -1) { break; } } Console.WriteLine("Text received : {0}", data); byte[] msg = Encoding.ASCII.GetBytes(data); handler.Send(msg); handler.Shutdown(SocketShutdown.Both); handler.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } api啊 sendmessage或postmessage 应该可以的 你准时写的类或者窗体标题不对. 不行,WebService调用sendmassage无效果。窗口句柄已正确获取 用过winform向webservice申请数据,没有用过从webservice主动发送数据到winform 已经改用Socket,webservice作为客户端,winform作为服务端,单机上调试成功。需求有了些变化,二者不在同一电脑上了。WebService在公网上,winform在可连接公网的局域网上。winform端socket的ip地址该如何写?应该是公网ip,但通讯如何到达局域网上的指定电脑?也就是说,winform的网络节点是: 222.241.12.45-->192.168.0.11,socket如何实现这个节点的通讯? 关于C#winform中Datagrid单击问题 vs2008里如何UML建模?有工具吗 是不是类关系图? (.cd扩展名) C# 怎么从文章里取出所有5位以上数字 ??? 求一个简单的正则表达式 c#用GDI+画曲线,请教 关于RichTextBox的Rtf问题(急!!!) DataTable,DataSet的问题,急! 请问这个圆为什么不圆啊 用DataSet读XML文件,提示类型转换错误怎么回事? 超简单的小问题,见笑了 十万火急!!!望大神指教 C语言用什么软件编程
byte[] bytes = new Byte[1024];
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1003);
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try
{
listener.Bind(localEndPoint);
listener.Listen(10);
while (true)
{
Console.WriteLine("Waiting for a connection");
Socket handler = listener.Accept();
data = null;
while (true)
{
bytes = new byte[1024];
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
if (data.IndexOf("<EOF>") > -1)
{
break;
}
}
Console.WriteLine("Text received : {0}", data);
byte[] msg = Encoding.ASCII.GetBytes(data);
handler.Send(msg);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
不行,WebService调用sendmassage无效果。窗口句柄已正确获取
也就是说,winform的网络节点是: 222.241.12.45-->192.168.0.11,socket如何实现这个节点的通讯?