This something like - anybody would think why I will require to do this thing ever?. I mean calling a web service without adding reference of it. Obviously, to call a web service I would simply add the "Web Reference.." from the Solution Explorer; select the web service and once I am done; I would create the object of the Web Service and use its method - As simple as that.
BUT, recently I came into a bit different scenario which I would like to share. While working on one of my DotNetNuke Solution - I require to have a web service inside my DotNetNuke project (in one of custom module) which is to be consumed by another application. The whole solution was a product which seem to be hosted at the potential customer's side (on their server) - with appropriate configuration. That means, while hosting the DotNetNuke application at the client side - a fresh installation (using Install version) is needed with whatever "Virtual Directory" name they prefer.
Here the problem starts; because every client may like to have different name/url of the application. That means, name of the "Virtual Directory" can be different at each client space. In this case, in another application which is consuming the web service - I need to modify the web reference as per the "Virtual Directory" name of the hosted DotNetNuke solution! That is not desirable. Another scenario to call a web service without adding web reference - I can think of - is to call a method from more then one web services based on some user input (That is - if you want to dynamically call appropriate web service method).
Anyways, I end up with to calling web method without adding web reference.
for the sake of simplicity, Below is the simple default web method "Hello World" which you will find while you add a web service in your solution.

Once you done with the web methods, you add the web reference where you actually consume the web service methods. When you add a web reference - based on the WSDL specifications IDE actually created proxy classes in your application which represents the web service classes and its methods on the remote server. Visual Studio provides Intellisense with Web services, which will not be accurate till you update your web reference each time you change your web service, it is because the proxy classes which are local to your solution are being used to offer you the Intellisense. So, ultimately when you invoke a Web method you are invoking a method in one of these proxy classes. These classes, in turn, are capable of invoking the remote methods on the Web Service URL.
So, every time the web service is updated, these proxy classes need to be regenerated by clicking Update Web Reference. However, the proxy classes do not always have to be generated from the IDE, .NET also gives us the WSDL.exe utility to manually generate these proxy classes and include them in your project.

To generate this proxy classes you need to generate these proxy classes thru "WSDL.exe" utility from Visual Basic Command Prompt.
Once you are done, notice that WSDL.exe utility has created a proxy class for our Test web service at "C:\Program Files\Microsoft Visual Studio 10.0\VC\WebService.cs
Just grab the class, create a new website and add that proxy class in App_Code folder. If you open the proxy class you will notice the constructor of the proxy class contains "url" member property which is by default assigned the url of the website in which the web service exists. You can store the web service url in web.config or in database or whereever you wish it to be.

So, finally to call the "Hello World" web method - you need to create object of this proxy class and assign the url property correctly as below:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebService objService = new WebService();
objService.Url =
System.Configuration.ConfigurationManager.AppSettings["WebServiceUrl"];
Response.Write("Output of the Web method call: " + objService.HelloWorld());
}
}
First we created object of the proxy class, assigned the url property value from web.config file's appsetting section and call the web method. Thats it!.Hope this would be helpful and informational to somebody who need the same.
Below is the output of our example application:

Conclusion: you can call web service method without adding reference by creating proxy class thru wsdl.exe utility.
Did you ever need to write disconnected process which should be run at a defined interval time? Commonly, when we are in such need - we use to write window service which is based on some timer mechanism where we set some interval for the timer and in its elapsed method we execute the process we want to run at defined interval.
When you work with DotNetNuke and you come across with such functionality that need tobe implemented - you can consider creating "DotNetNuke Scheduler". While creating a DNN Scheduler - you are actually creating a simple class library which would be built and hosted in the DNN Schedule environment to be executed at the defined interval time.
The possible scenario in which one need to look at such schedule functionality is:
[1] You may need to send some set of fixed newletter everyday at defiend time to your customers.
[2] You may need to read some of third party product feed to read regular update and modify your product database.
[3] You may need to send some system generated reports to your third party vendor at some regular intervals.
To Create a DNN Scheduler; you need to:
[1] Create a class library project with a class which inherits DotNetNuke.Services.Scheduling.SchedulerClient.
[2] Write the process which you wish to be executed at some interval and call it in DoWork() method. (You can consider the DoWork() method as entry point of the disconnected process execution.
[3] Build the class library project and get th dll.
[4] Copy the dll inside /bin directory of your DNN solution.
[5] Make an entry in DNN Schedule (Host menu > Schedule submenu) service and host the dll by giving proper namespace and the elapsed time.
Let us explore above step in some details.
First step is to create a class library for which you need to add a new class library project inside your DNN solution.

Once you add the class library; just rename/modify the namespce, classname and the class filename which is appropriate to your DNN Solution. Like I modified the namespace and classname as: YouProjectName.ModuleName.TestSchedule
The namespace is important to define correctly as it will be used later on to define the entry in DNN Schedule.
Next, you need to add DotNetNuke.Library (DotNetNuke.dll) reference to your class library by right click class library project in the solution explorer and "Add Reference.." option. Once you add the DotNetNuke.Library reference you would be able to access DNN namespaces and classes which would be require to access DNN related functions and methods.
After adding reference, you need to inherit "DotNetNuke.Services.Scheduling.SchedulerClient" abstract class and implement DoWork() overridable method.


Here, I am also adding a parameterized constructor to properly record the schedule history:

For ease, I am creating a simple "Hello World" function which would create a new txt file at the defined path specifying current date and time.
public override void DoWork()
{
try
{
//--start the pocessing
this.Progressing();
//--call the function/process that you wish to be executed
ExecuteHelloWorld();
//--intimate the schedule mechanism to write log note in schedule history
this.ScheduleHistoryItem.AddLogNote("HelloWorld Service Start. Success.");
this.ScheduleHistoryItem.Succeeded = true;
}
catch (Exception Ex)
{
//--intimate the schedule mechanism to write log note in schedule history
this.ScheduleHistoryItem.Succeeded = false;
this.ScheduleHistoryItem.AddLogNote("HelloWorld Service Start. Failed. " + Ex.ToString());
this.Errored(ref Ex);
}
}
//--function which needs tobe executed at specified interval
public void ExecuteHelloWorld()
{
try
{
System.IO.File.WriteAllText(@"C:\\_SCHEDULER\\test" + Guid.NewGuid().ToString() + ".txt",
"Hello World. The Time is - " + DateTime.Now.ToString());
}
catch (Exception Ex)
{
throw Ex;
}
}
If you look at the above code - The processing always start from DoWork() method where I am calling the ExecuteHelloWorld() function. This is the function which will be executed at the defiend interval. Here, I am also logging in the Schedule history which would help us to know the status of the schedule execution.
Thats it!. You are done with the coding part. Next, all you need to do is; build the class library project get the dll, copy inside /bin directory of DNN solution and host it under DNN Schedule. For that Go to "Host" menu > "Schedule" submenu option. Once you are there, you would see there are some schedule entries already exists in the list which are being used in DotNetNuke environment


You would see a list of scheduled processes with its name, current status (enabled or disabled), the frequency of the execution, the next run as well as link to see the "Execution History". To add our process; Click on the "Add Item to Schedule" link. You will be redirected to "Edit Schedule" page where in you need to add your process to schedule.

[1] Give "Friendly Name" of the schedule process which will be seen in the schedule list.
[2] Provide full classname with namespace along with the assembly name. For example, in our case it will be YouProjectName.ModuleName.TestSchedule,TestSchedule. Please note that you dont need to write ".dll" extension; just full classname and name of assembly (dll) followed by a comma separator. This entry should be correct.
[3] Check the checkbox to enable the schedule.
[4] Provide the interval time to execute the process
[5] Provide the retry interval time; incase of failure.
[6 ] Specify the number of records in "Retain Schedule History" for History listing.
[7] You can specify "Run On Event" which will show Global.asax events; incase if you want schedule to execute the process on a specific event of global.asax. For example, APPLICATION_START event.
[8 ] Check the checkbox "Catch Up Enabled"; incase if you want the schedule process tobe executed in a scenario like the webserver is ever out of service, when the webserver is back in service this event will run once for each frequency that was missed during the downtime.
Click on the Update and you will see the newly hosted process in DNN Schedule list. You can click on "History" link to see the history of the execution. On History page, you will be presented with detailed Hisory records which we logged in our class library. This will helps to know the status of scheduled process.

Here, some important note is that A DotNetNuke Scheduler can have 2 running modes:
[1] Request Mode - in which DotNetNuke Scheduler will execute and run each time ONLY when a Browser Request is made.
[2] Timer Mode - in which DotNetNuke Scheduler will execute and keep running behind the scene on the specified elapse time.
By default, "Request Mode" is set which you can change from "Host" Menu > "Host Setting" submenu > Other Setting section > and Scheduler Mode Dropdown.

Thats it!. I hope this would help a lot to one who needs to implement continuous background process execution in DNN environment.
Oh Yes!,, The output of our test Schedule :)
