This is a simple web service that is passed a string and then writes the string to a text file on the server.
This is a cool way to have error messages sent to one place from remote locations.
Here are the major steps
1 Create a folder on your web server named 'newfolder' and create empty file named textfile.txt
2 Create a bin folder inside the newfolder...path should be /newfolder/bin
3 Now make the newfolder a virtual directory inside Internet Information Server
4 Make sure the virtual directory is an application root.
Now your web server is ready for the dll in the /bin directory and the asmx file
5 Create a new project in Visual Studio 2008
6 Make the new project a ASP.NET Web Service Application
Now look in the Solution Explorer and find the Service1.asmx
Open the Service1.asmx.c
now the code behind file can be seen and should look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "
http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
We are going to change it to this:
using System;
using System.Collections.Generic;
using System.IO
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "
http://nippersoftware.com/webservices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public void WriteToFile(String Message)
{
StreamWriter writer = new StreamWriter(@"d:\yourwebsitepath\newfolder\textfile.txt");
writer.WriteLine(Message);
}
}
}
Now the webservice has a member named WriteToFile that will accept a string as the parameter.
Build the project and make sure no errors.
Now copy the project .dll to the newfolder\bin directory
Copy the .asmx file to the root of newfolder
Make sure you have permissions and the web.config file does not block access to the newfolder directory.
Now the server for the web service next we have to set up the client, or 'consume' it. Were just going to use it!
The client:
Create a new project in Visual Studio 2008. Make it a Windows forms application
Drag a Button control onto the form and make a click event.
The click event will handle the calling of the web service but first we have to set a reference to it
1. open references in Solution Explorer
2 Click Add Service Reference

This will open the Add Service Reference Dialog

Enter the URL for the webservice and click "go"
You will see the WriteToFile Member
Now click ok. The reference should be added to the Solution Explorer

Now we must use in code:
using System;
using Webservice1.ServiceReference1;
namespace MyNamespace
{
class WebServiceConsumer
{
public void SendtoWebService(String MyStringToSend)
{
WritetoFileClassSoapClient myTest = new WritetoFileClassSoapClient();
try
{
myTest.WriteToFile(MyStringToSend);
}
catch
{
//do nothing
}
}
}
}
My pleasure
Ken