| Thomas's profileBlogsBlogLists | Help |
|
|
11 September Connection to a web service (the simplest way):Accessing to an existing web service in .NET is as easy as it can be: Remember the previous generated web service that has the following members
Now let the service run in the background and create a new form application. Then, In the solution explorer you select "Add new web Reference..." from the context menu. In the dialog, type in the url adress of the running web service (in this example it's "http://localhost:1122/WebSite2" and then you'll see the directory list, where you select "service.asmx" and then you finally need to click the button "Add Reference" and a new file "localhost" is added to your form project in the Web References section on the solution explorer. Now you can simply access all methods of the web services as simple as accessing to properties of an object. See a simply example here: private void button1_Click(object sender, EventArgs e) /// Call a method form the web service. That' all! So within one minute, you can access all methods of an existing web service. By the way, the web reference (in this example named localhost) provides 2 method access members for each method on the web service:
private void button1_Click(object sender, EventArgs e) /// Add an event that occures when the web service has finished to process the /// now executhe the Merge method asynchronously: /// <summary> 05 September Creating a Web Client to access a previousely created Web ServiceAfter creating our first web service, we are no prepared to access it's members using HTML Post functionality, which goes like this: private void button1_Click(object sender, EventArgs e) As you see, the two params for the Merge member are specified in a NameValueCollection class, while the HttpPost is done by calling WebClient.UploadValues which returns a byte[] value, that represents an xml string that looks like followed: <?xml version="1.0 encoding="utf-8"?><string xmlns="http://tempuri.rog/">Merged VR with Developpers!</string> Of course you'll have to to some additional stuff, but this is the simple way to access a web service in .NET. Note that the 1882 port may differ, so you might change it. Just click on the tool tray icon of the running web service to see it's current port number. Creating a Web Service in .NETCreating a simple web service within Visual Studio 2005 is done in a view minutes:
[WebService(Namespace = "http://www.tomsblog.de/", Description = "For testing purposes only")] } [WebMethod(Description="Returns a counter value as string")] [WebMethod(Description="Merges to strings to one.")] Now you know how to access the web service and how to create a web client comes with the next blog... |
|
|