05
Thu, Dec
6 New Articles

Microsoft Computing: .NET Web Services

Microsoft
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Part of Microsoft's grand design for the way computer users conduct business includes the concept of using .NET Web services. This month, I present a primer in .NET Web services, some background information, and an example program that uses Web services.

In ".NET Web services" the word "services" does not mean what it does in other computer contexts, such as that of a background task like a printing daemon. In this context, a "Web service" is a server computer on a network that has been set up to deliver some specific information on request. A Web service, then, is much like an Internet Web site--but for computer programs, rather than for people using a browser. Even so, the process of getting information from a Web service provider is much like the process a person would use--looking up a URL, finding the needed information, and returning.

What makes using a Web service in a program so compelling is the close relationship between Web services and .NET programming languages. Almost all of the grisly details of distributed object integration and remote services brokering inherent in platforms like CORBA and COM have gone under the covers since the improvements in the .NET and Web services integration model.

The mother of all Web services is BizTalk, from (whom else) Microsoft. BizTalk offers a wide range of Web services like "systems integration, business-to-business transaction processing, and business process management." Many other Web service providers supply explicit pieces of information. For instance, there is a Web service to provide a list of Irish legal holidays, another for prime numbers, and another for movie theatres in your area. And most Web services are available at no charge. All you have to do is create a C# or VB.NET program that references the Web service. The Web service will then be treated in your program as if it were a local object that has an exposed interface of methods and properties. You may then set properties and invoke methods to send the request and receive the reply.

Some Web Services Basics

Just as Web content information coming to a browser for display is formatted as HTML, data coming from a Web service for consumption by a requesting program is formatted as XML. The request and response is conducted over your Internet connection using a transaction protocol called Simple Object Access Protocol (SOAP). But fear not! You don't have to learn much about XML or SOAP to use a Web service in a C# or VB.NET program.

Microsoft Visual Studio (VS) has the capability of helping you create a VB or C# application that can access standard services available on the Web. VS will help you find an appropriate Web service and then build an interface for that particular service automatically, using specifications published by the Web service provider. The specifications are published in a language called Web Service Description Language (WSDL). When you create a reference to the service in your program, the WSDL is examined, and the appropriate interface is created. The Web service's public properties and methods are discovered and incorporated into the program.

But before you can access the information from a Web services provider, you have to know where to send your request. The Universal Description, Discovery, and Integration (UDDI) service is a central repository of listings where Web service providers may register their servers and where those in need of services may get a referral to a service provider.

A Simple Web Service Application

For example, suppose you were writing a simple Windows program that would allow a user to type in a name and address for the purpose of producing a set of mailing labels. You want to help the user with this task, so you decide to include a customary feature in your program whereby the user keys in a ZIP code, and the computer looks into a PC file for the city and state that correspond to the ZIP code and offers them to the user. It's been used for years. Assuming you acquire the ZIP code data from, say, the Postal Service and get the solution working, it won't be long before problems arise as your ZIP file falls out of date. The Postal Service creates new ZIP codes and changes existing ZIP codes all the time. To solve this problem, you could get a refreshed ZIP code file from the Postal Service at regular intervals, or you could build your program so that it asks a standard Web service to get the ZIP code information for you. The standard Web service provides this support on behalf of the Postal Service to many users, free of charge, and the ZIP code information is accurate and current.

This C# example will send a request to the ZIP code Web Server and display the response:

http://www.mcpressonline.com/articles/images/2002/Microsoft-WebServicesV3--10240500.jpg
(Click images to enlarge.)

To see how a program like this is built, start a new C# or Visual Basic project in Visual Studio 2003 or later. In the Solution Explorer window, right-click References and select Add Web Reference. This will launch a browser-like wizard that will help you find an appropriate Web service.

http://www.mcpressonline.com/articles/images/2002/Microsoft-WebServicesV3--10240501.jpg

If you know the name of the Web service, you can key it into the URL box, as in the figure, or you can browse the UDDI directory. In this example, I use a Web service provided for educational purposes by Glenn Johnson Technical Training. Click the Go button, and the wizard will discover and return the specifics for the Web service. The Web reference name for the service is then displayed (com.teachatechie in this case). Click on Add Reference. After a bit, the new Web reference is added to the Solution Explorer. Double-clicking the reference name will display the object browser for the new Web service object, and the methods and properties for the Web service will be shown just as if the service was a local resource.

http://www.mcpressonline.com/articles/images/2002/Microsoft-WebServicesV3--10240502.jpg

From this point, it's a matter of generating some code to create an instance of the Web server object, getting a ZIP code from the user, passing the request, and getting the response. The example code below is invoked when the user keys a ZIP code into a text box and clicks the Lookup button:

        private void btnLookup_Click(object sender, System.EventArgs e)
        {
            string sWork;
            int ib = 0;
            int ie = 0;

            Cursor.Current = Cursors.WaitCursor;

//  Create a dataset to receive the city/state info...
            DataSet s = new DataSet("ZipCode");

//  Create a ZIPcode Web Service object...
            com.teachatechie.ZipCode t;
            t = new com.teachatechie.ZipCode();

//  Invoke the ZIPcode object's GetLocation method,
// passing the ZIP code to be looked up...
            s = t.GetLocation(txtZip.Text);

//  Get the XML representation of the dataset in a string...
            sWork = s.GetXml();

//  Dump the raw XML into a label control 
//    just to see what it looks like...
            lblsWork.Text = sWork;

//  Put the first city/state name into labels for display...
ib = sWork.IndexOf("");
            ib = ib + 12;
            ie = sWork.IndexOf("/CITYSTNAME>", ib);
            ie = (ie - ib) - 1;
            lblCity.Text = "";
            if (ie > 0)
            {
                lblCity.Text = sWork.Substring(ib, ie);
            }
            
ib = sWork.IndexOf("");
            ib = ib + 7;
            ie = sWork.IndexOf("/STATE>", ib);
            ie = (ie - ib) - 1;
            lblState.Text = "";
            if (ie > 0)
            {
                lblState.Text = sWork.Substring(ib, ie);
            }
            
            Cursor.Current = Cursors.Default;
        }


Notice that a dataset object must be created to accept the response from the server. This is necessary because the server may return 0, 1, or many records (in the figure, two cities, Seattle and Times Square, are returned for a single ZIP code).

The response will be in XML format, but that's not a problem thanks to .NET's XML handler. Notice the GetXml method that will render the dataset content as a string, which may then be parsed.

Some Considerations for Using Web Services

Naturally, there are some problems inherent with using Web services. Obviously, there can be no Web services if there is no connection, so an application of this sort cannot function in a standalone form. Also, what happens if the Web services host is not functioning properly? If your application is entirely dependent on Web services being available, there may be times when your application doesn't function at all. Another factor to consider is what may happen when a given Web service provider changes the formatting of the returned information. And what if the provider gets out of the Web services business altogether?

As Web service platforms become more mature and established, the practice of incorporating Web services into production applications will become more accepted. There may come a day when dozens or even hundreds of this type of resource will be routinely regarded as viable and essential tools for building your .NET applications.

Chris Peters has 26 years of experience in the IBM midrange and PC platforms. Chris is president of Evergreen Interactive Systems, a software development firm and creators of the iSeries Report Downloader. Chris is the author of i5/OS and Microsoft Office Integration Handbook, The AS/400 TCP/IP Handbook, AS/400 Client/Server Programming with Visual Basic, and Peer Networking on the AS/400 (MC Press). He is also a nationally recognized seminar instructor and graduate instructor at Eastern Washington University. Chris can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..

Chris Peters has 32 years of experience with IBM midrange and PC platforms. Chris is president of Evergreen Interactive Systems, a software development firm and creators of the iSeries Report Downloader. Chris is the author of i5/OS and Microsoft Office Integration Handbook, AS/400 TCP/IP Handbook, AS/400 Client/Server Programming with Visual Basic, and Peer Networking on the AS/400. He is also a nationally recognized seminar instructor and a lecturer in the Computer Science department at Eastern Washington University. Chris can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Chris Peters available now on the MC Press Bookstore.

i5/OS and Microsoft Office Integration Handbook i5/OS and Microsoft Office Integration Handbook
Harness the power of Office while exploiting the i5/iSeries database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: