Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Wednesday, March 28, 2012

Web Service

I want to write webservice which would just get output from stored procedure (=XML) and send it as XML out. And true is that I realy don't know how to do that. I'm not sure if output from webservice will be string or sthing else.It is easy way to make a Web Service.
1. First , Create a Web Application. such like "http://localhost/webService"
2. Second, Add a new service from solution: Add New Item, select "Web Service", such like: WebService1.asmx.

3. In this page, default has a function, you need to uncomment it.

[WebMethod]
public string HelloWorld()
{
return "Hello World"; // You can return your XML format string. What you returned is just what the client will get.
}

4. You can make your function and return what you want.
5. Set this file as start page, then build it.
6. Run and test it.

7. In client side, such like WinForm, you need add a web reference. On project's references, right click mouse, in popup menu, select "Add Web Reference";

8. Type the web site and page file , such like : http://localhost/webService/WebService1.asmx, then click "go"

9. In "Web Reference Name", put the name you like to name it,such like: "myWebService", then OK.

10. In a WinForm Page, call web server and see what you get.
the code like this:
myWebService.Service1 service = new myWebService.Service1();
string result = service.HelloWorld();
If your response is a XML file, the result string will be the XML string.