Get Started with XML Web Services
Số trang: 9
Loại file: pdf
Dung lượng: 19.31 KB
Lượt xem: 13
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Bắt đầu với 13,1 XML Web Services Tôi có nghe nói một số điều tuyệt vời về XML Web Services, nhưng tôi không biết làm thế nào để bắt đầu. Tôi phải làm gì để bắt đầu làm việc với XML Web Services?
Nội dung trích xuất từ tài liệu:
Get Started with XML Web Services 13.1 Get Started with XML Web ServicesI have heard some great things about XML Web Services, but I dont know how to getstarted. What do I do to get started working with XML Web Services?TechniqueThe best way to get started with XML Web Services is to simply create your own XMLWeb Service and start playing with it. Visual Studio .NET makes it extremely easy to dojust that. To achieve this task, you will be creating your first Web Service, which, ofcourse, will be Hello World. Now, before you start groaning, this example will show youthe basics of creating a Web Service without a lot of other fluff that gets in the way andconfuses things.Creating a Web ServiceThe way you start to create a Web Service is to choose ASP.NET Web Service for a newproject. When you have done this, VS will create the Web Service project, and you willbe brought to what looks like a blank Web Form, as displayed in Figure 13.3. Figure 13.3. Here is a newly created Web Service project.Note Remember: Web Services can be created in various ways. Because you are creating this one using Visual Studio .NET, you will be using ASP.NET to create it.For the most part, you will be using Web Services to provide central processes orfunctionality that you want to be consistent regardless of where you consume it from.This means that you will not be creating a user interface that users will see; you arebasically creating a class-like interface that will provide methods (hence the use ofService1.asmx instead of *.aspx). You will use *.asmx as an entry point for your WebService.To really get going with working with your first Web Service, you will click on the ViewCode icon in the Solution Explorer. When you do so, you will see the first method tocreate. Thats right-it is Hello World. The first thing you should do now is uncomment thelines of code that read as follows: Public Function HelloWorld() As String HelloWorld = Hello WorldEnd FunctionThe screen should look like Figure 13.4. Figure 13.4. Your first Web Service method.Thats it! You have created your first Web Service method. Now its time to test it.Testing the Web ServiceAfter you have created your Web Service, click the Start toolbar button. Visual Studiowill then compile and build your Web Service. After which, Visual Studio will create atest page for your Web Service, as shown in Figure 13.5. Figure 13.5. This page that Visual Studio created gives you instructions on how to specify a namespace for your Web Service within the calling application.Note As mentioned on this Web page, when you are developing your Web Service, Visual Basic uses a temporary namespace called http://tempuri.org/. When you are going to make the Web service public, you will want to create different namespace for the Web Service. I would recommend just using the examples they give on your test Web page.One of the items you see on this test Web page is the list of operations, otherwise knownas methods you created. If you click on the Hello World method, you will see anotherpage that you will use to invoke the actual method (see Figure 13.6.) Figure 13.6. This page allows you to test your Hello World method.You also will see example code for calling the method using SOAP, HTTP GET, andHTTP POST. However, you will just be using this test page to check out the Hello Worldexample, and you will be learning how to call methods from Visual Basic behind WebForms in How-To 3.3.If you click on the Invoke button, you will see the following:Hello WorldThis is the value that the method you created returns. Thats it! Thats all there is to thetest page.Note Before telling yourself that this test page doesnt do much, remember that if you did have a problem with the code in your Web Service, the problem would have shown up here. This quick testing saves a lot of hassle of writing code that actually calls the methods and then making sure the calling code wasnt causing errors. Using the test page allows you to debug your Web Service before you integrate it. Okay, I am now off my SOAPbox. Pun intended.Looking at the Description of the Web ServiceVisual Studio .NET saves you from a lot of work. If you click the Back button and go tothe main test page, you will see a link to Description in the top sentence. If you click onthis link, you will see the SOAP code shown in Listing 13.1.Listing 13.1 http://localhost/WebService1/Service1.asmx?WSDL: Soap Definitionfor Your First Web Service- - - - - - - - - - - ...
Nội dung trích xuất từ tài liệu:
Get Started with XML Web Services 13.1 Get Started with XML Web ServicesI have heard some great things about XML Web Services, but I dont know how to getstarted. What do I do to get started working with XML Web Services?TechniqueThe best way to get started with XML Web Services is to simply create your own XMLWeb Service and start playing with it. Visual Studio .NET makes it extremely easy to dojust that. To achieve this task, you will be creating your first Web Service, which, ofcourse, will be Hello World. Now, before you start groaning, this example will show youthe basics of creating a Web Service without a lot of other fluff that gets in the way andconfuses things.Creating a Web ServiceThe way you start to create a Web Service is to choose ASP.NET Web Service for a newproject. When you have done this, VS will create the Web Service project, and you willbe brought to what looks like a blank Web Form, as displayed in Figure 13.3. Figure 13.3. Here is a newly created Web Service project.Note Remember: Web Services can be created in various ways. Because you are creating this one using Visual Studio .NET, you will be using ASP.NET to create it.For the most part, you will be using Web Services to provide central processes orfunctionality that you want to be consistent regardless of where you consume it from.This means that you will not be creating a user interface that users will see; you arebasically creating a class-like interface that will provide methods (hence the use ofService1.asmx instead of *.aspx). You will use *.asmx as an entry point for your WebService.To really get going with working with your first Web Service, you will click on the ViewCode icon in the Solution Explorer. When you do so, you will see the first method tocreate. Thats right-it is Hello World. The first thing you should do now is uncomment thelines of code that read as follows: Public Function HelloWorld() As String HelloWorld = Hello WorldEnd FunctionThe screen should look like Figure 13.4. Figure 13.4. Your first Web Service method.Thats it! You have created your first Web Service method. Now its time to test it.Testing the Web ServiceAfter you have created your Web Service, click the Start toolbar button. Visual Studiowill then compile and build your Web Service. After which, Visual Studio will create atest page for your Web Service, as shown in Figure 13.5. Figure 13.5. This page that Visual Studio created gives you instructions on how to specify a namespace for your Web Service within the calling application.Note As mentioned on this Web page, when you are developing your Web Service, Visual Basic uses a temporary namespace called http://tempuri.org/. When you are going to make the Web service public, you will want to create different namespace for the Web Service. I would recommend just using the examples they give on your test Web page.One of the items you see on this test Web page is the list of operations, otherwise knownas methods you created. If you click on the Hello World method, you will see anotherpage that you will use to invoke the actual method (see Figure 13.6.) Figure 13.6. This page allows you to test your Hello World method.You also will see example code for calling the method using SOAP, HTTP GET, andHTTP POST. However, you will just be using this test page to check out the Hello Worldexample, and you will be learning how to call methods from Visual Basic behind WebForms in How-To 3.3.If you click on the Invoke button, you will see the following:Hello WorldThis is the value that the method you created returns. Thats it! Thats all there is to thetest page.Note Before telling yourself that this test page doesnt do much, remember that if you did have a problem with the code in your Web Service, the problem would have shown up here. This quick testing saves a lot of hassle of writing code that actually calls the methods and then making sure the calling code wasnt causing errors. Using the test page allows you to debug your Web Service before you integrate it. Okay, I am now off my SOAPbox. Pun intended.Looking at the Description of the Web ServiceVisual Studio .NET saves you from a lot of work. If you click the Back button and go tothe main test page, you will see a link to Description in the top sentence. If you click onthis link, you will see the SOAP code shown in Listing 13.1.Listing 13.1 http://localhost/WebService1/Service1.asmx?WSDL: Soap Definitionfor Your First Web Service- - - - - - - - - - - ...
Tìm kiếm theo từ khóa liên quan:
công nghệ máy tính phần mềm kỹ thuật lập trình lập trình dữ liệu XML Web ServicesGợi ý tài liệu liên quan:
-
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 247 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 187 0 0 -
Giới thiệu môn học Ngôn ngữ lập trình C++
5 trang 180 0 0 -
6 trang 171 0 0
-
Luận văn: Nghiên cứu kỹ thuật giấu tin trong ảnh Gif
33 trang 147 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 145 0 0 -
Báo cáo thực tập Công nghệ thông tin: Lập trình game trên Unity
27 trang 115 0 0 -
Giáo trình về phân tích thiết kế hệ thống thông tin
113 trang 113 0 0 -
LUẬN VĂN: Tìm hiểu kỹ thuật tạo bóng cứng trong đồ họa 3D
41 trang 104 0 0 -
Bài giảng Kỹ thuật lập trình - Chương 10: Tổng kết môn học (Trường Đại học Bách khoa Hà Nội)
67 trang 102 0 0