488 Patterns: Extended Enterprise SOA and Web Services
how to obtain this additional material, see Appendix A. "Additional material" on
page 481.
Microsoft Visual Studio .NET 2003 is packaged with an application called
wsdl.exe. It parses a WSDL file and other files referenced in the WSDL, and
generates a C# skeleton based on the WSDL interface.
1. Copy the contents of the \dotNET\resources directory from the additional
material supplied with this Redbook to a temporary directory on your local
machine.
2. Click Start Programs Microsoft Visual Studio .NET 2003 Visual
Studio .NET Tools Visual Studio .NET 2003 Command Prompt.
3. In the resulting command prompt, navigate to the location of the temporary
directory where you extracted the additional material.
4. Enter the following command:
wsdl.exe /server Manufacturer.wsdl Configuration.xsd ManufacturerPO.xsd
ManufacturerSN.xsd envelope.xsd
The output should look similar to Example B-1:
Example: B-1 wsdl.exe command output
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Writing file 'C:\Temp\output.cs'.
We now have a template C# source code file to use as the foundation for our
Web service that is called output.cs.
B.2.3 Modifying the C# file
The code in output.cs contains an abstract class for the Web service becasue
we chose to use the /server option when running the wsdl.exe application.
Therefore, we must edit the C# code directly in order to turn the abstract class
into a concrete one. We must also make additional modifications to the code so
that Web service consumers will have information returned to them when they
call it using SOAP/HTTP.
Note: For more details on the wsdl.exe application and how it functions,
including a list of all usable attributes, please visit:
http://msdn.microsoft.com/library/en-us/cptools/html/cpgrfWebServ
icesDescriptionLanguageToolWsdlexe.asp
Appendix B. Microsoft .NET Web services 489
1. Open the output.cs file in a text editor.
2. Make the first necessary modification to the code by removing the two
abstract statements, which are seen bolded in Example B-2:
Example: B-2 The output.cs abstract class modifications
[System.Web.Services.WebServiceBindingAttribute(Name="ManufacturerSoapBinding",
Namespace="http://www.ws-i.org/SampleApplications/SupplyChainManagement/2002-10
/Manufacturer.wsdl")]
public abstract class ManufacturerSoapBinding : System.Web.Services.WebService
{
public ConfigurationType Configuration;
public StartHeaderType StartHeader;
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("Configuration")]
[System.Web.Services.Protocols.SoapHeaderAttribute("StartHeader")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("ackPO",
Namespace="http://www.ws-i.org/SampleApplications/SupplyChainManagement/2002-10
/ManufacturerPO.xsd")]
public abstract string
submitPO([System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.ws
-i.org/SampleApplications/SupplyChainManagement/2002-10/Manufacturer" +
"PO.xsd")] PurchOrdType PurchaseOrder);
}
3. In addition, remove the semicolon at the end of the ManufacturerSoapBinding
class (its located in the second to last line shown in Example B-2) and add the
following C# code:
{
return “Manufacturer_B has received and processed a request.”;
}
This simple return statement is what the Web service will return to the consumer.
4. Finally, we must comment some of the generated source code in order to
avoid errors when the Web service is targeted by the J2EE consumer.
Comment out these two lines by adding comment marks (//) in front of them:
[System.Xml.Serialization.XmlAttributeAttribute(Namespace="http://schemas.x
mlsoap.org/soap/envelope/")]
public bool mustUnderstand;
490 Patterns: Extended Enterprise SOA and Web Services
5. Now, with these modifications made, the two main sections of changed code
should be identical to Example B-3, except where the text returned to the
Web service consumer is customized to the users preference.
Example: B-3 Final code for the output.cs C# source code file
[System.Web.Services.WebServiceBindingAttribute(Name="ManufacturerSoapBinding",
Namespace="http://www.ws-i.org/SampleApplications/SupplyChainManagement/2002-10
/Manufacturer" +
".wsdl")]
public class ManufacturerSoapBinding : System.Web.Services.WebService {
public ConfigurationType Configuration;
public StartHeaderType StartHeader;
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("Configuration")]
[System.Web.Services.Protocols.SoapHeaderAttribute("StartHeader")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("ackPO",
Namespace="http://www.ws-i.org/SampleApplications/SupplyChainManagement/2002-10
/Manufacturer" +
"PO.xsd")]
public string
submitPO([System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.ws
-i.org/SampleApplications/SupplyChainManagement/2002-10/Manufacturer" +
"PO.xsd")] PurchOrdType PurchaseOrder)
{
return “Manufacturer_B has received and processed a request.”;
}
}
...
//[System.Xml.Serialization.XmlAttributeAttribute(Namespace="http://schemas.xml
soap.org/soap/envelope/")]
//public bool mustUnderstand;
...
Important: The first and second lines of the code displayed here appear
on one line in the actual source code.

Get Patterns: Extended Enterprise SOA and Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.