Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

Is it possible for a windows service to call a web service? Have successfully added a web reference to the web service and I am running the windows service, but it seems to be having no effect.

 

Any suggestions?

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Have a web service for sending SMS messages via the Http, hoping to use the windows service to call the web service every 5 minutes to send the messages in the message queue. Don't know where the problem is occuring. The web service is working correctly as I am using it with a standard windows application. Must look into the windows service as the problem might be there.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

I had the same problem in the same situation, also tried to send sms through webservice, but this one was located on a linux server, I am going to look at my project to see how I've solved it,

 

Greetz

Posted

Does the web service attempt to perform any user authentication, and could this be failing due to it running under the system user account rather than as a normal user?

 

Can you easily test the part of the windows service that calls the web service as a standalone application running as the current user, and does this work?

 

Regards

Richard

Posted

This is the code I used, nothing to fancy just using a timer to call the webservice every 8000, and according to the result of the parsing I call another webservice to send the message.

 

#pragma once

using namespace System;
using namespace System::Collections;
using namespace System::ServiceProcess;
using namespace System::ComponentModel;
using namespace System:: Diagnostics;
using namespace GsoapSMS;
using namespace MessagingSystem; 
using namespace System::Text;


namespace CheckSMS
{
/// <summary> 
/// Summary for CheckSMSWinService
/// </summary>
///
/// WARNING: If you change the name of this class, you will need to change the 
///          'Resource File Name' property for the managed resource compiler tool 
///          associated with all .resx files this class depends on.  Otherwise,
///          the designers will not be able to interact properly with localized
///          resources associated with this form.
public __gc class CheckSMSWinService : public System::ServiceProcess::ServiceBase 
{
public:
	CheckSMSWinService()
	{
		InitializeComponent();    
	}
	/// <summary>
	/// Clean up any resources being used.
	/// </summary>
	void Dispose(bool disposing)
	{
		if (disposing && components)
		{
			components->Dispose();
		}
		__super:: Dispose(disposing);
	}
private:
	bool stopping;
	int loopsleep;              //milliseconds
	Threading::Thread* servicethread;
private: System::Timers::Timer *  tmrCheck;
		 sms *LocalSMS;

protected:
	/// <summary>
	/// Set things in motion so your service can do its work.
	/// </summary>
	void OnStart(String* args[])
	{
		Threading::ThreadStart* threadStart = new Threading::ThreadStart(this,mainLoop);
		servicethread = new Threading::Thread(threadStart);
		servicethread->Start();
	}

	void mainLoop()
	{
		loopsleep = 10000;       //milliseconds
		stopping = false;
		LocalSMS = new sms();
		
		ArrayList *list = new ArrayList();
		while (!stopping)
		{
			
			if(tmrCheck->Enabled == false)
				tmrCheck->Enabled = true;
			Threading::Thread::Sleep(loopsleep);
		}
     }


	void ParseMessage(SmsInfo* info)
	{

		if(info->Message->StartsWith("[u]"))
		{
			SyntraWebService *msging = new SyntraWebService();
			StringBuilder *strBuild = new StringBuilder();
			System::Object* list[] = msging->AllContacts();
			for(int i=0;i<list->Count;i++)
			{
				strBuild->Append(list[i]->ToString());
				if(i < list->Count -1)
					strBuild->Append(",");

			}
			LocalSMS->SMSSend(info->Number->ToString(),strBuild->ToString()); 
		}
		
	}

	/// <summary>
	/// Stop this service.
	/// </summary>
	void OnStop()
	{     
		stopping = true;
	}
   		
private:
	/// <summary>
	/// Required designer variable.
	/// </summary>
	System::ComponentModel::Container *components;

	/// <summary> 
	/// Required method for Designer support - do not modify 
	/// the contents of this method with the code editor.
	/// </summary>	
	void InitializeComponent(void)
	{
		this->tmrCheck = new System::Timers::Timer();
		(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->tmrCheck))->BeginInit();
		// 
		// tmrCheck
		// 
		this->tmrCheck->Enabled = true;
		this->tmrCheck->Interval = 8000;
		this->tmrCheck->Elapsed += new System::Timers::ElapsedEventHandler(this, tmrCheck_Elapsed);
		// 
		// CheckSMSWinService
		// 
		this->CanPauseAndContinue = true;
		this->ServiceName = S"CheckSMS";
		(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->tmrCheck))->EndInit();

	}		
private: System::Void tmrCheck_Elapsed(System::Object *  sender, System::Timers::ElapsedEventArgs *  e)
		 {
			 SmsInfo* SmsRetval;
			 do
			{
				if((SmsRetval = LocalSMS->SMSCheck())!= 0)
				{
					ParseMessage(SmsRetval);
				}
			}while(SmsRetval->NbrofSms > 0);
		 }

};
}

 

greetz

Posted

Hadn't though of that, will have a look at it as every other thing seems to be working correctly, i.e. the web service works correctly when I call the web methods from IE. There is no errors occuring with the windows service, as I have set it up that it will restart the machine on the first error.

 

Mike55

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...