无法使用C#通过Windows服务将数据发送到服务器 [英] Not able to send data to server through Windows Service using C#

查看:55
本文介绍了无法使用C#通过Windows服务将数据发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C#中使用WiX应用程序创建了 Windows服务,以自动将数据发送到服务器。所以,我使用线程来捕获数据并将数据发送到服务器。以下是我的代码。

  protected   override   void  OnStart( string  [] args)
{
trd = new 线程( new ThreadStart(ThreadTask));
trd.IsBackground = true ;
trd.Name = 我的工人线程;
trd.Start();
}

public void ThreadTask()
{
while true
{
SendData();
Thread.Sleep( 3000 );
}
}

public void SendData( )
{
// 以下是通过HttpWebRequest将数据发送到服务器的代码。
}





我正在使用 HttpWebRequest 进行数据发送。此应用程序能够以调试模式将数据发送到服务器,但是一旦在通过WiX 构建setup .msi文件后正常运行此应用程序,Windows服务正常启动但应用程序不发送数据。我在测试OnStart方法下的函数内部的一个简单文件时,我也测试了线程通过服务正常运行。



这是一个问题周互联网或其他事情正在发生。一方面服务运行良好,另一方面数据已成功发送 在调试模式下,只有没有调试数据不通过服务发送。请尽快帮助我完成这项工作。



任何形式的帮助都将受到高度赞赏。



提前谢谢。

解决方案

你用过fiddler

http://www.telerik.com/download/fiddler [ ^ ]

查看在HTTP级别发生的事件,请求/响应等。可能是访问权限问题(仅限于以为)。

I have created a windows service in C# with WiX application to send data to the server automatically. So, I have used thread for capturing and sending the data to the server. Below is my code.

protected override void OnStart(string[] args)
{
    trd = new Thread(new ThreadStart(ThreadTask));
    trd.IsBackground = true;
    trd.Name = "My Worker Thread";
    trd.Start();
}

public void ThreadTask()
{
    while (true)
    {
        SendData();
        Thread.Sleep(3000);
    }
}

public void SendData()
{
    // Here is the code to send data to the server through HttpWebRequest.
}



I am using HttpWebRequest for data sending. This application is able to send the data to the server in Debug mode, but as soon as I run this application normally after building the setup .msi file through WiX, the Windows Service gets started normally but the application does not send the data. Whereas I have also tested that the thread is running fine through service when I put a simple file write in the thread inside a function under OnStart method.

Is it a matter of week internet or something else is happening. At one hand the Service is running well, on the other hand data is successfully sent in Debug mode, only that without Debug, data is not sent through Service. Please help me get through this as soon as possible.

Any kind of help will be highly appreciated.

Thanks in advance.

解决方案

Did you use fiddler
http://www.telerik.com/download/fiddler[^]
See whats happening at an HTTP level, request/response etc. Probably an access rights issue(just a thought).


这篇关于无法使用C#通过Windows服务将数据发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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