Professional Documents
Culture Documents
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:17 AM
Color profile: Generic CMYK printer profile
Composite Default screen All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 /
Blind Folio 2
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:17 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
The Technologies
In this chapter, you will
CHAPTER
25
• Be introduced to SOAP, UDDI, XML, WSDL, XSLT, XPath, and XSD
• Configure debugging in an XML web service
• Implement logging in an XML web service
• Implement tracing in an XML web service
This chapter introduces you to the concepts that we will be exploring in detail in this part
of the book. In order to fully understand the questions you will see on Exam 70-320,
“Developing XML Web Services and Server Components,” you must take the time to un-
derstand the protocols and alphabet soup that you see in this chapter’s objectives. Most
of the questions are very detailed and explore complicated scenarios that will call upon
your understanding of the technologies.
As a result, you will see very little in this chapter that is directly on the exam; however,
you will need to know this chapter inside and out to be successful on the exam. If you
are fairly new to XML (Extensible Markup Language), be sure to review the information
in Chapter 8. We will quickly review the concepts here, but we will also be going into the
detail that is required for the 70-320 exam. A fair bit of this chapter will be spent on
SOAP (Simple Object Access Protocol), and then we will briefly explore technologies
such as UDDI, XSLT, XPath, and XSD.
We will also take some time to review the testing methods for XML web services and
server components. In Chapter 9, we looked at the generic concepts related to testing—
creating a unit test plan, tracing, and so forth. In this chapter, we will specifically con-
sider the testing of an XML web service. We will also look at the log test results. The focus
of our work on testing in this chapter will be on debugging control within the
web.config file and using SOAP extensions for debugging.
The Standards
Many of the questions on the 70-320 exam describe complicated scenarios that require
your understanding of the standards involved in server-based services. In this section,
we will examine some of these standards and protocols. Here is a quick summary:
• XML (Extensible Markup Language) A language that allows data and data
definitions to be included in a structured document.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:17 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
In this section, we will start with XML and work our way through the preceding list.
Remember that most of the information in this section is provided as a reference for the
material that comes after it. You will see very little on the exam that is directly related to
this section.
What Is XML?
XML stands for Extensible Markup Language and was designed to describe data. Since it
is a markup language, it looks a little like HTML (Hypertext Markup Language), but it is
not the same thing. HTML is used to display data and XML is used to describe data. XML
uses tags that you define (or that a schema document defines) to define pieces of data
within the XML document. The following is an example of an XML document:
<recipe>
<name>Chicken Soup</name>
<ingredient>Chicken</ingredient>
<ingredient>Soup</ingredient>
</recipe>
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:18 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
XML Rules
As a standard, XML boasts very simple and very tight syntax rules. Following these rules
means that your XML document can be easily read and used. These rules are as follows:
• The first line in the document is an XML declaration describing the version and
encoding:
<?xml version="1.0" encoding="utf-8"?>
PART V
• There can only be one root element. An element is a tag that describes the data,
and in a well-formed XML document, there is only one root element. The root
element in our example is <recipe>.
Figure 25-1
The XML
document in
Internet Explorer
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:18 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
XML Elements
Elements are the most common type of markup that you will see in an XML document.
Elements describe the data and formulate the hierarchy of the data in the document.
Tags are used to define data elements. In between the start tag, <element_name>, and
the end tag, </element_name>, is the actual text or data that belongs to the element.
In this example, Chicken Soup is the data:
<name>Chicken Soup</name>
Elements can be hierarchical. This means that you can have child elements of an ele-
ment. In our earlier example, <ingredient> was a child of <recipe>, and <name>
was a child of <recipe>. To be more correct, you may want to formulate the XML doc-
ument like this:
<recipe>
<name>Chicken Soup
<ingredient>Chicken</ingredient>
<ingredient>Soup</ingredient>
</name>
</recipe>
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:18 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
XML Attributes
An XML attribute can be used to give more information about the data. However, an at-
tribute is not an element. Rather, it is a part of the element and gives more information
about the element. In the earlier example, we used this line to describe the data regard-
ing the name of the recipe:
<name>Chicken Soup
We could add an attribute (which is simply a named pair of values) to give more infor-
mation about the name of the recipe:
Category is the attribute, and it is followed with an equals sign (=) and double quotes
surrounding the value. You can use either double or single quotes to surround the at-
tribute value, but they must match.
PART V
For more information on XML, refer back to Chapter 8. However, keep in mind that
this book’s intention is not to teach you XML. You simply have to know how it is formed
and how it is used in web services or server components.
What Is SOAP?
Many developers were keen to anticipate the release of SOAP since they were looking for
a method of using RPCs (remote procedure calls) over HTTP (Hypertext Transfer Proto-
col). Remote procedure calls are used by many different distributed solutions to define
the way requests and data are transmitted from one application to another. This means
that one program can request the services of another program that is located on a remote
system. The calling program (client) does not need to understand the network details.
How the request gets there is unimportant to the client.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:18 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
• The envelope The envelope describes what is in the SOAP message and
explains how the message can be processed.
• The encoding rules The encoding rules define the serialization mechanism
(encoding, sending, and decoding) that can be used to exchange the data.
• The RPC representation This is the convention that can be used to represent
remote procedure calls and the responses from the server.
Let’s look at how a SOAP message is created, and how the mechanism works.
The Envelope Every SOAP message is an XML document. The document includes
an XML envelope element, which is the root element (see Chapter 8 for the definition of
root elements). The envelope element optionally may contain a header element, but
must contain a body element. If a header is not used, the body element must be the im-
mediate child of the envelope element.
EXAM TIP A SOAP message is made up of (1) the envelope, the top element
in the XML document that represents the message; (2) the header, an optional
element that includes definitions of extra features; and (3) the body, a mandatory
element that contains the message.
The SOAP header is used to describe extra information regarding the message but will
not directly affect the message. Some of the information that you might find in a SOAP
header includes the following:
• Transaction information
• Authentication information
• Language, country, currency, etc.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:18 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
The SOAP body is the actual message that is intended for the recipient of the message.
The body element will contain multiple child elements, which are called body entries.
SOAP Encoding Serialization (the rules for representing types such as integers,
strings, and so forth) of data inside a SOAP message is called encoding. You can use an at-
tribute called encodingStyle within the Envelope element to identify the encoding
rules. Encoding style can be defined right down to a specific element, if you want. How-
ever, we won’t spend too much time on this concept because you’ll begin to think that
the “Simple” in SOAP is a misnomer.
There is no default encoding style, but you can use the SOAP specification’s set of en-
coding rules. These will work well in most cases since they map nicely to most program-
ming types. The SOAP encoding rules are found at http://schemas.xmlsoap.org/soap/
encoding/.
To read more on SOAP encoding, refer to the SOAP specifications at http://
www.w3.org/TR/SOAP. Section 5 covers the rules for encoding types in XML, simple
types, strings, enumerations, compound types, arrays, structs, and references.
RPC Representation The final piece that brings the picture together is the repre-
sentation that defines the convention that can be used to represent method calls and re-
sponses. For the purposes of this part of the book, we will cover SOAP in HTTP. Keep in
mind, however, that SOAP can be used for remote procedure calls (RPCs). The SOAP
specification (http://www.w3.org/TR/SOAP) covers both of these.
PART V
The SOAP Message
Figure 25-2 shows how a SOAP message is constructed. Notice that HTTP (the transpor-
tation protocol) wraps the entire message. Within the package is the SOAP document,
and it contains an optional header with delivery information and a mandatory body
with the actual method parameters.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:19 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
<SOAP:Envelope xmlns=http://schemas.xmlsoap.org/soap/envelope/>
<SOAP:Body>
<m:helloWorld xmlns:m="http://www.osborne.com/"/>
</SOAP:Body>
</SOAP:Envelope>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema
xmlns:tns=http://schemas.xmlsoap.org/soap/envelope/
targetNamespace="http://schemas.xmlsoap.org/soap/envelope/">
- <!--
Envelope, header and body
-->
<xs:element name="Envelope" type="tns:Envelope" />
<xs:complexType name="Envelope">
<xs:sequence>
<xs:element ref="tns:Header" minOccurs="0" />
<xs:element ref="tns:Body" minOccurs="1" />
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="lax" />
</xs:complexType>
<xs:element name="Header" type="tns:Header" />
- <xs:complexType name="Header">
- <xs:sequence>
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xs:complexType>
<xs:element name="Body" type="tns:Body" />
- <xs:complexType name="Body">
- <xs:sequence>
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xs:sequence>
- <xs:anyAttribute namespace="##any" processContents="lax">
- <xs:annotation>
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:19 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
In this code you can see the schema that describes some of the elements and attributes
that will be included in your SOAP document. For the complete schema, go to http://
schemas.xmlsoap.org/soap/envelope.
Here is a template for a SOAP message:
<SOAP:Envelope xmlns:"http://schemas.xmlsoap.org/soap/envelope/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP:Header>
<!--
Header information goes here
e.g.
<t:Transaction xmlns:t="URL" /t:Transaction>
-->
</SOAP:Header>
<SOAP:Body>
<!--
Body goes here
e.g.
<m:runMethod xmlns:m="URL" />
-->
<SOAP:Fault>
<!--
Fault information goes here
Carries error and/or status information within a SOAP message
e.g.
PART V
<faultcode>SOAP:Server</faultcode>
<faultstring>Server Error</faultstring>
-->
</SOAP:Fault>
</SOAP:Body
</SOAP:Envelope>
SOAP in HTTP
Developers can use SOAP within HTTP. SOAP and HTTP are a natural fit, since they
both use a request/response messaging model. In this section, we will examine how you
can bind SOAP to the network protocol, HTTP. Keep in mind that a lot of this is beneath
the surface of what you see when you code using Visual Studio .NET and create web services.
SOAP allows you to embed method calls within an XML document and have those
calls transmitted over HTTP. Here are the steps:
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:19 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
<?xml version="1.0"?>
<SOAP:Envelope xmlns:"http://schemas.xmlsoap.org/soap/envelope/>
<SOAP:Body>
<m:getRecipe xmlns:m="namespace:IRecipe">
<recipeName>Chicken Soup</recipeName>
</m:getRecipe>
</SOAP:Body>
</SOAP:Envelope>
Notice that within the <SOAP:Body> element, the element <m:getRecipe> matches
the SOAPMethodName in the HTTP header. (Remember that <m:getRecipe> translates
into <namespace:IRecipe:getRecipe>.) Because of this, the code within HTTP
can be used to process the call on the server side without having to parse the XML first.
We have added one more element to the SOAP message—<recipeName>. This is
the parameter information that the method getRecipe is expecting. So, what happens
at the server side? The SOAP protocol doesn’t really care. The request may be to an ASP
page or any other server component, such as Java Server Pages, CGI programs, Apache
modules, and so on. The point here is that it doesn’t matter what is on the server side.
That’s the beauty of SOAP—it’s transparent to the server. Issues like interoperability,
firewalls, and the like all disappear by using SOAP.
This is a very simplified explanation of SOAP, mainly because you don’t need to
know all of the mechanics behind it.
EXAM TIP Microsoft will ask you questions regarding the protocol to use
when requesting services outside of the local application. Your answer very
often should be SOAP. Read the question carefully and ensure that SOAP
will answer the problem.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:19 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
SOAP messages are embedded in an HTTP request. The message is sent to the server
identified by its URL in the message. Figure 24-3 illustrates the process.
SOAP in HTTP is used to provide an interoperable, standards-driven, and flexible
transmission of message calls between a client and a server. XML web services use SOAP
as the protocol for network messages. These messages can pass data and use complex
structures, such as objects and structures.
PART V
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:19 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
of the web service provider. The location is returned to the consumer, who then makes
the remote call to the web service provider. The provider services the request and returns
the response to the consumer.
XML web services use HTTP, XML, and SOAP. Since the protocols are easily trans-
ferred throughout the World Wide Web, XML web services are gaining in popularity and
will ultimately replace many of the older standards, such as DCOM, CORBA, and so
forth. XML web services can be used by virtually any application since the technologies
are platform-independent.
It is not always necessary to use XML web services—XML web services operate at a
higher level of networking, which requires extra overhead. However, if you have little or
no control over the location of the client or the server, you will find that the answer to
platform limitations is to use XML web services.
The web service consumer must be able to create the messages that are destined for
the web service and understand the messages that are returned from the web service. Al-
though it is possible to do the coding yourself, it is much easier to allow the .NET Frame-
work to build the proxy class that will encapsulate the message-parsing and creation
code. The idea behind a proxy is that it works on behalf of the application and acts as
a go-between between the technology and the application.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:20 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
Unless you like to type, you can get the .NET Framework to generate this file for you.
Let’s look at creating a simple web service.
1. Open a new ASP.NET Web Service project in Visual Studio .NET, and name it
CImperial. Be sure to locate the project on the localhost server (or your
web server of choice).
2. Rename the file to Imperial.asmx in the Solution Explorer.
PART V
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:20 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:20 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
6.
Add the code to tell the service its namespace (see Figure 25-7). This step is
required to locate the service correctly.
7. Build and run the solution (F5) and click on the Service Description link that
appears in the web browser. You will see the WSDL file that has been created
for you. You can see in Figure 25-8 that the methods have been described in
this file. This document is the contract between the provider and the consumer
of the web service.
PART V
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:20 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
Now that you have created the web service provider, you need to build the client. The
following steps describe how build the client (the web service consumer):
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:20 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
PART V
4. Press ENTER, and you will see the window shown in the following illustration.
This window allows you to select from the web services found at the location in
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:20 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
5. When you expand the Web References and localhost sections in the Solution
Explorer, you will see the WSDL file that has been created for you.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:21 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
PART V
a new instance of the web service and then call on its HelloWorld() method.
The result is shown in the following illustration.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:21 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
Consider the World Wide Web and all of the services located there. How is an appli-
cation developer to find out about the web services that are available? In order to help in
the search for XML web services, XML web service directories are used. Web services are
published to the directories, and the information is then available to any queries.
The UDDI (Universal Description, Discovery, and Integration) specifications define
the standards for publishing and discovering information about XML web services.
These standards have been built in cooperation with companies such as Microsoft,
Ariba, Novell, and IBM (to name but a few). For more information on the UDDI specifi-
cations, visit http://uddi.org/.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:21 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
• XML Schema for Business Descriptions includes information about the service
publisher (contact name, address, and so on) and specifications on the
web service.
• Web Registry of Web Services includes business, service, and binding information
for the web service.
Think of UDDI as a yellow-pages service. Businesses register their web services with
UDDI, which in turn publishes them for use by consumer applications. The consumer
applications can then search for the available web services and receive information
about them.
Let’s look at the process of discovering information about web services. The follow-
ing steps describe what happens when a consumer application searches for and finds
a web service directory:
PART V
5. The consumer then requests that a method be executed by sending a SOAP
message that encompasses the SOAP request for the method.
6. The provider then returns a SOAP response with the results of the method
invocation.
In the HelloWorld consumer example created in the “Creating a Web Service” section
of the chapter, you right-clicked on the project and selected Add Web Reference from the
menu, and you saw the screen shown in the following illustration. Notice that, there are
currently two UDDI directories listed there—the UDDI Business Registry and the
Microsoft development directory. When you select the UDDI Business Registry, you will
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:21 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
In the following illustration, we typed in Microsoft as the business name and then ex-
panded the root UDDI Web Services to receive the namespaces you see in the list.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:21 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
This is simply an example of how the process works when you statically select a
UDDI directory. Remember that dynamic discovery will return information about web
services that might not be statically known.
PART V
EXAM TIP To add discovery capabilities to your .NET application, add the
System.Web.Services.Discovery namespace to the application.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:21 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
<recipe>
<name>Chicken Soup
<ingredient>Chicken</ingredient>
<ingredient>Soup</ingredient>
</name>
</recipe>
We can take this file and add the XSD to it, as follows:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Recipe" type="RecipeType"/>
<xsd:simpleType name="RecipeType">
<xsd:sequence>
<xsd:element name="RecipeName" type="xsd:string"/>
</xsd:sequence>
<xsd:simpleType name="Ingredient">
We could start to make a lot of mistakes by doing it this way. Let’s look at how Visual
Studio .NET assists us in the process:
1. Open a new file in Visual Studio (File | New File). This file can be added to an
existing project or be created on its own. You will see the New File dialog box.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:22 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
2. Select XML Schema from the list of templates and click Open.
3. The new file is shown in Figure 25-9. Notice that the Toolbox has a new tab—
XML Schema. From the Toolbox, you can select and drag any of the following
XML Schema descriptors to the Design window: element, attribute, attributeGroup,
complexType, and so forth.
4. Experiment by adding a complexType called Recipes, and insert the element’s
name and ingredient. When you switch over to the code window, you will see
the code shown in Figure 25-10.
PART V
In order to link your XML file to the XSD file, add the following to the recipe.xml file:
<?xml version="1.0"?>
<RecipeSummary RecipeSummary="MyRecipes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file://MyFirstXSD.xsd">
<recipe>
<name>Chicken Soup
<ingredient>Chicken</ingredient>
<ingredient>Soup</ingredient>
</name>
</recipe>
</RecipeSummary>
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:22 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
Notice that in this example we have no namespace for the XML. We are simply pointing
to the local filesystem for the .xsd file. Properly formed XML and XSD would include
namespaces to identify locations.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:22 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
PART V
XSLT documents are stored in style sheets that are used to transform the XML data.
Let’s look at our recipe XML file and combine it with an XSL style sheet.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Recipe.xsl"?>
<recipe>
<name>Chicken Soup
<ingredient>Chicken</ingredient>
<ingredient>Soup</ingredient>
</name>
</recipe>
</RecipeSummary>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:22 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
Once a parser program (such as MSXML) works through the XML file, it outputs an
HTML file, as shown here:
<html>
<body>
<H1>
Chicken Soup
</H1>
<li>Chicken</li>
<li>Soup</li>
</body>
</html>
The style sheet contains the templates that tell the parser how to process the XML.
These templates could tell the parser to work with the data or, as in our example, create
the HTML to display the data.
System.XML Namespace
In order to use these technologies programmatically, you need to know the classes that
represent them. The System.XML.XSL namespace is where you will find the classes
that are used to perform XSLT transformations. These include
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:22 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
The System.Xml.XPath namespace contains the classes that allow XPath expres-
sion parsing and evaluating. Look for
This whole section has been a quick introduction to the technologies that you will
use with XML. Keep the various acronyms in mind as you go through the rest of the
chapters in this part of the book. You will be able to see where they are used and how
they are used as we cover the requirements for exam 70-320.
PART V
services that you create, and you will find that information in the chapters that focus on
each service. The next chapter, for instance, is on Windows Services, and you will find
a section on testing in that chapter.
<compilation
defaultLanguage="c#"
debug="true"
/>
EXAM TIP By setting the debug attribute to True, the debug information
will be compiled into your solution. Be sure to change this attribute before
you deploy your application.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:22 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
You should also ensure that the project configuration shows ASP.NET Debugging as
enabled. Right-click on the project in Solution Explorer and select Properties from the
menu. You will see the Property Pages dialog box shown in the following illustration.
Select the Configuration Properties on the left side, and set the Enable ASP.NET De-
bugging option to True.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:22 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
PART V
nent information to the log file without recording too many events that would cause the
file to explode.
In order to write to the Application Log, add the following namespace declaration:
using System.Diagnostics
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
The System.Diagnostics namespace contains classes that allow you to write to the
Application Log. In the section of your web service, locate the method that contains
the error (or write an error-handling routine) and add the following:
This method will now write a message out to the Application Log after checking if the
log file actually exists first. If the log file does not exist, this method will create it with
this line:
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
if (HttpContext.Current.Trace.IsEnabled == True)
{
HttpContext.Current.Trace.Write ("MyWebService", "We are here!");
}
This code will check the context under which the service is running (the configuration
PART V
file sets the context) and determine whether it should write the tracing information out
or not.
To set the runtime environment, code the following in the web.config file:
Turn off the pageOutput property, since normally this tracing is found at the bottom
of an HTML page. An XML web service is not typically outputting any HTML, so the in-
formation will not be seen.
Summary
In this chapter, we have provided you with an introduction to the technologies that will
be explored throughout this part of the book. We have looked at XML again and re-
viewed the technologies associated with it. We have also explored the concepts and im-
plementation of Simple Object Access Protocol (SOAP).
EXAM TIP Remember that these technologies, SOAP, HTTP, and XML,
work together to provide XML web services.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
Test Questions
1. What is the result of opening the following XML file in Internet Explorer?
<Books>
<Book>
<Title>
All-in-One Certification Guide
</Title>
</Book>
</Books>
A. The file will not open because it is not well-formed XML.
B. Figure 25-13.
C. Figure 25-14.
D. An XML file cannot be opened by Internet Explorer.
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
2. Which line of code will write an event out to an Event Log file?
A. EventLog.CreateEventSource (strLogName, strMessage);
B. EventLog.WriteEntry (strMessage,
EventLogEntryType.Error);
C. eventLogInstance.WriteEntry (strMessage,
EventLogEntryType.Error);
D. EventLog.Source = eventLogInstance.WriteEntry
PART V
(strMessage, EventLogEntryType.Error);
3. Which namespace must be added to the XML web service in order to write to
an event log?
A. System.EventLog
B. System.Events
C. System.Diagnostics
D. System.Diagnostics.Event
4. Which technology allows you to publish XML web services?
A. XMLPub
B. XSLT
C. XPath
D. UDDI
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
PART V
D. WebService MyWebService = new WebService();
MyWebService.Method();
10. How would you add a web service component to your Visual Studio .NET
application?
A. Project | Add Web Component
B. Project | Add Component
C. Project | Add Web Service
D. Project | Add Service
11. A static discovery file will usually have a file extension of which of the
following?
A. .vsdisco
B. .vdisco
C. .sdisco
D. .disco
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
25
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
25
PART V
P:\010Comp\All-in-1\443-6\ch25.vp
Monday, August 26, 2002 11:52:23 AM