Web hosting window asp

Web hosting window asp

ASP Programe About Us Links Downloads Contact Us Terms of use SiteMap
Web hosting window asp
Web hosting window asp

 

You are here: ASP Programe >>Web hosting window asp

Web hosting window asp article lists.

Web hosting window asp

Creating a Web Service




XML Web Services are emerging as the next big thing in software development. Based on open Internet standards and backed by vendors including IBM, Microsoft, and Oracle, Web services will let developers build distributed applications that work across diverse environments.

An XML Web Service is a language-independent, platform-independent, self-describing code module that applications can access via a network or the Internet. The application can have the service's location hard-coded or can locate it using UDDI (Universal Description, Discovery, and Integration). Because the service is self-describing, the application can determine which functions are available and how to call them. Typically the service offers specific information, such as the current rental price for a Lincoln Town Car in Las Vegas. Powerful applications will be built using loosely coupled groups of XML Web Services; that's the idea, anyway.

Microsoft Visual Studio .NET (VS .NET), the latest version of the company's Visual Studio development environment, makes development, testing, and deployment of XML Web Services absurdly simple. In this article, we'll walk you through the process of creating an XML Web Service, deploying it, and writing a Web-based program to utilize it. (This article describes the Beta 2 version of VS .NET; the released version may differ in various ways. For a detailed look at VS .NET, please see "Inside Visual Studio .NET" in our issue of September 4.)

Planning Ahead for Deployment

When you install VS .NET, it loads and configures the system components required for local hosting of XML Web Services and other Web-based applications. Such a feature is extremely convenient for iterative development and debugging. But sometime between the early development stages and the final deployment on the company Web site, you'll need to test your project on a nonlocal server. VS .NET anticipates such a necessity with built-in access to Web-hosting solutions (some are free and others require a subscription). For the purposes of this article, we used a free account on the Brinkster service. To build the sample programs yourself, you will need the same type of account.

If the Start page isn't visible in VS .NET, select Show Start Page from the Help menu. Click the Web Hosting link on the left-hand side, and VS .NET checks for any updates to the list of available hosting services. To create a free account, click the Hosting Services tab, click the Signup with Brinkster link, and follow the prompts. Brinkster requires free accounts to use the naming convention membername_projectname for uploaded projects, so wherever you see membername in the examples below, substitute your member name.

Creating the Web Service

For this demonstration, we'll create a simple service that provides random answers to yes-or-no questions, much like the old Magic 8 Ball toy. Launch VS .NET and choose File | New | Blank Solution from the menu. Name the solution membername_magicball, then click OK (Figure 1). If the Solution Explorer is not visible, select it in the View menu. Right-click the new solution in Solution Explorer and choose Add | New Project... from the pop-up menu. Select Visual C# Projects in the Project Types list on the left-hand side (don't worry, you don't need to be a C# master). Select ASP.NET Web Service in the Templates list on the right-hand side. You'll notice that the location field below changes to http://localhost. Give this project the same name as the solution, membername_magicball (Figure 2).

VS .NET immediately creates several files related to the project; the most important of these is service1.asmx. In the Solution Explorer, rename the file magic.asmx. Now open the Class View, expand the project, and select the class named Service1. Change its Name property to magic in the Properties window (Figure 3). Double-click magic.asmx to activate the editor window. Then right-click the editor and choose View Code to see the C# source code that VS .NET generated.

Scroll down a bit and you'll see a commented out "Hello World" example. Delete it and add this simple method (we'll flesh it out later):

[WebMethod] public string Answer(string Question) { return Question + " Of course!"; }

The [WebMethod] attribute indicates that the method should be exposed as part of the XML Web Service. Amazingly, the service is now 100 percent functional. To prove this, launch the project by pressing F5. Your browser should open to a page that lists the operations available in this service (Figure 4) . One operation, Answer, corresponds to the Web method of the same name. Clicking the Answer link displays an elaborate page, which contains both input fields for testing the operation and examples of calling the operation using SOAP and HTTP. Enter a question and click the Invoke button. You'll receive the return value from the Answer function in the form of an XML fragment. For example:

<?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://tempuri.org/">Should I write more XML Web Services? Of course!</string>

Now that we know the service works, we'll give the Answer function some more interesting responses. The modified function checks the beginning of the question for specific keywords and randomly selects from a set of appropriate answers. We'll take advantage of C#'s jagged arrays—arrays in which the elements are themselves arrays of varying dimensions and sizes. Start by deleting the line that begins return Question and add this code:

string[][] keywords = new string[][] { new string[] { "CAN I", "Yes, you can", "No, you can't", "Ability unclear"}, new string[] { "WHEN", "Time is a river", "You will know the time"}, new string[] { "(NO KEYWORD)", "Yes", "No", "Perhaps", "Ask again later"} };

Note that the three sample elements of the keywords array are themselves arrays, each of a different size. Devise more subarrays and insert them before the final (NO KEYWORD) entry. In each case, the first element should be an uppercase word or phrase that might begin a question, and the remainder should be answers that would be appropriate to such a question. Now add the following code:

string CleanQ = Question.Trim().ToUpper(); int i; for (i = 0; i < keywords.GetUpperBound(0); i++) if (CleanQ.StartsWith(keywords[i][0])) break; int iFrom = keywords[i].GetLowerBound(0)+1; int iTo = keywords[i].GetUpperBound(0); Random R = new Random(); return keywords[i][R.Next(iFrom, iTo)];

If you're not familiar with C#, the code above may look rather peculiar. As in Java, all data types in C# are objects. Instead of calling string library functions, you call methods of the string class. For example, the Trim() method returns the string without leading or trailing blanks, ToUpper() returns an uppercase copy of the string, and StartsWith() returns True if the string starts with the passed value. The for loop sets the variable ito the index of the keyword that began the question, or to the last index if there are no matches. Then the function returns a random answer from the set of responses for that keyword. Launch the service again and try invoking the Answer operation with a few yes-or-no questions.

Going Public

At this point, the service is functional only on your local host, but it's ready for a test deployment to the Internet. If the Start page isn't visible, select Show Start Page from the Help menu. Click Web Hosting, then click the Hosting Services tab, and then click Upload directly to your Brinkster account. The Brinkster account is the one you created earlier. Click the Upload button on the Project Upload tab and wait until the process is complete. That's all—you've deployed your solution.

Now you just need to locate your project's exact address. Navigate your browser to www .brinkster.com, log on, and click the File Mgr link. Open the membername_magicball folder, select the magic.asmx file, and click the View button. The page that appears should look familiar, because it's the same page you saw when you ran the service locally. Instead of http://localhost, however, its URL will be something like www#.brinkster.com/membername/ membername_magicball/magic.asmx, with # representing a number. Click the Answer link and try passing a few questions to the service. To ensure that the service is running on the Web and not on your local host, e-mail the URL to a friend or launch it on another computer.

Consuming the Service

Web hosting window asp Related Links
Web hosting asp mysqlAsp hosting nick.com web
Asp canada hosting php webWeb hosting asp sql
Asp access web hostingAsp hosting php web
Web hosting asp supportDedicated asp hosting
Asp web hosting servicesAsp free hosting net web
Asp .net web hostingAsp dedicated hosting web
Asp free hosting site webAsp hosting service web
Asp free frontpage hosting webAsp free ftp hosting
Access asp free hosting webAsp exchange hosting
Asp asp.net hosting webHosting asp access
Microsoft asp web hosting1000mb asp hosting web
Asp hosting u webAsp australia hosting web
Asp host hosting webAsp net hosting free
Asp buffalo hosting webAsp hosting formules
Asp hosting planAsp hosting site web woodinville
Asp hosting virginia webAsp canada hosting ms sql
Asp hosting mysql site webAsp domain free hosting name
Asp web hosting arizonaAsp free ftp hosting web
Asp hosting servicesAsp hosting seattle site web
Asp hosting shared windowAsp bellevue hosting site web
Application asp hostingAccess asp free hosting
Asp free ftp hosting mysqlAsp hosting redmond site web
.net asp free hosting webApache asp free hosting web
Asp free hosting mysql webAsp hosting server
Asp hosting server sqlAccess asp database free hosting
 
©2005 All Rights Reserved   ASP Programe