In my previous
column I presented a style of writing WSDL files that, when
followed, resulted in reusable components and a nice service-oriented
architecture. Pedants may complain that I was essentially proposing
rpc/literal rather than doc/literal by
requiring that every request and response had a name determined
algorithmically from the operation name. There are two responses to
this: first, since you can have attributes it's not RPC; second, who
cares?
In this column we'll actually build a web service using the style, as well as the examples, from the previous column. Again, we'll use Norm Walsh's where in the world service. For grins, we'll look at a C#/.NET client and a Python server.
Getting Started
The .NET stub generator is called, interestingly enough,
wsdl. The first step is to stitch together the fragments
from last time and build a single WSDL file that we can feed into the
wsdl program. The only thing missing is the schema
definition. As I first discussed in September
of 2003, use the "Russian Doll" pattern, which eschews the XSD
type system for inlining definitions. Also, reuse structures based
on element name, not type.
Looking at the nearby operation, we see the following
"calling sequence":
nearby(
xs:string userid,
xs:string units = "mi",
xs:decimal distance = 50.0)
This isn't a C++-like description, since either or both of
userid or distance can be omitted.
This description, using the above style, results in the following
schema declaration:
<xsd:element name="nearby">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="userid" type="xsd:string"/>
<!-- units defaults to "mi" -->
<xsd:element name="units" type="xsd:string" minOccurs="0"/>
<!-- distance defaults to "50" -->
<xsd:element name="distance" type="xsd:decimal" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
This is, admittedly, verbose, with nine lines of definition. The return value, which is an array of a complex type, is almost twice as long, and pretty heavy on the XSD-specific overhead:
<xsd:element name="nearby-response">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="landmark">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="latitude" type="xsd:float"/>
<xsd:element name="longitude" type="xsd:float"/>
<xsd:element name="distance" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Just looking at those first half-dozen lines is enough to make you
think of the Monty Python "spam" sketch. In defense, I can only
point out that it's pretty boilerplate, and that you can pull out
the landmark definition into its own element declaration,
and use the ref attribute:
<xsd:element ref="tns:landmark" minOccurs="0" maxOccurs="unbounded"/>
Which method you use is a matter of taste. I typically inline the element if it's only used once.
Putting it all together, a complete WSDL can be found in listing 1.
Simple, elegant, unsupported
So if we feed our first WSDL into wsdl, we get
Error: Unable to import binding '&COMPONENT;-binding' from namespace '&BASE;'.
- Unable to import operation 'nearby-operation'.
- The element '&BASE;:nearby' is missing.
It turns out that my nice little scheme to use DTD's and ENTITY
declaration, so that I only have to write things like the namespace URI
once, and so that I can make a skeleton WSDL and edit a few lines at the
beginning before filling in the details...isn't supported. In fact,
just having a DOCTYPE with a few entities (even if they're never used)
gives the .NET wsdl tools fits
I don't recall the WS-I profile saying you shouldn't use a DTD in a WSDL file.
So we have to edit the code from listing
1 and replace the entities with their values. If you do that,
wsdl does the right thing, generating a C# client stub.
The stub turns the "where in the world" service into a class and
each operation becomes a method, which is pretty standard (although
it's pretty nice when coupled with VisualStudio's auto-completion
features).
Since our operations all take a sequence, wsdl also
creates an object for each input and output message. Putting them
together, we can write code like this:
witw b = new witw();
b.Url = "http://os360.datapower.com:4444/test/server";
@is i = new @is();
i.userid = "rsalz";
isresponse ir = b.isoperation(i);
Notice how you can change where the server is by setting
the Url property on the binding, b.
Also note that wsdl appends response or
operation to distinguish among request data, response
value, and operation.
For those who don't know C#, the atsign is a token-level quoting
character. In this case is is a C# keyword, so you have to
write it as @is. You will almost definitely face this kind
of issue when creating your own services -- no doubt you'll end up using
an identifier that's a keyword in some language, somewhere. Hopefully
the WSDL toolkit(s) for the language in conflict will have a mapping
mechanism. If not, or if it's too ugly (by some metric), you'll have to
edit your service description. Using mixedCase or under_scores will
probably avoid that kind of problem.
Messy, messy
Let's look at the atlandmark operation. Its allows a user
to specify that they are at a particular landmark. (For example, is
everyone in your dinner party over at Fry's Electronics?)
The function definition is this:
atlandmark(
xs:string userid,
xs:string landmark)
But this is what you end up having to write as code:
atlandmark l = new atlandmark();
l.landmark = "Fry's Electronics";
l.userid = "rsalz";
b.atlandmarkoperation(l);
That's a hell of a lot more ugly than the obvious:
b.atlandmark("Fry's Electronics", "rsalz");
More from Rich Salz |
What happened? Unfortunately, it's fallout from the way I wrote the WSDL. Every operation has a single input parameter and a single output parameter. That means your language bindings have to create "objects", or at least containers, to hold what would be the bits of XML on the wire. That's kind of ugly, but it's the dirty little secret of SOA: your system will be better off, but you will have to write more code.
If we compile and run the code (available in listing 2), and capture what it sends, we'll see that things make sense (I pretty-printed the message; it was sent as a single long line):
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<atlandmark xmlns="http://www.example.org/witw">
<userid xmlns="">rsalz</userid>
<landmark xmlns="">Tidepool</landmark>
</atlandmark>
</soap:Body>
</soap:Envelope>
Sure enough, we're shipping around a clean bit of XML. Granted, there are spurious (and redundant) namespace declarations there, but that's a small nit. (Bonus points if you can figure out which attribute in the schema definition caused the innermost empty namespace declarations.) And look, it's SOAP 1.1!
Next time we'll look at the server and discuss the joys of method dispatch.
|
Related Reading Real World Web Services |
Share your experience in our forums.
(* You must be a member of XML.com to use this feature.)
Comment on this Article
| Titles Only | Titles Only | Oldest First |
- Spurious Redundancy
2005-05-26 09:32:02 SparHawk [Reply]
Hi Rich,
Two points:
1. Can't access the listings; I get an error saying the pages can't be found.
2. Do you mean that the xmlns="" attributes are redundant namespace declarations? I can't see any others that might qualify, but, these are not redundant to my eye. I believe their scope is limited to the element on which they reside and any unqualified child elements. The effect of these declarations is to leave both the userId and landmark elements unqualifed; in no namespace. This would seem to render this response invalid with respect to the schema you have provided. Of course, I am unable to actually validate it since the schema listing is not available.
Thanks for the article. It's nice to see alternatives to WSDL being bandied about.
- Spurious Redundancy
2005-06-01 10:27:54 Rich Salz [Reply]
The webmasters fixed the broken links, thanks for noticing! And the spurious xmlns are the xsd and xsi at the top. The internal xmlns="" are because of the schema's elementFormDefault setting.
- Spurious Redundancy
- userid or distance can be omitted.
2005-06-14 16:58:12 ricka [Reply]
I think you meant:
units or distance
- Best Book on SOA Security
2006-07-27 07:55:13 dbrainar [Reply]
Can anyone out there suggest a good book on SOA Security? I'm interested in learning more.
- Best Book on SOA Security
2006-08-04 00:35:22 ramrs [Reply]
You might like to Pre Order this one -
www.manning.com/kanneganti/
http://www.amazon.com/gp/product/1932394680/002-3839929-0106440?v=glance&n=283155
- Best Book on SOA Security
2007-01-26 04:39:11 johnvixen [Reply]
Or this one
http://www.studentbunk.com/student-accommodation/product-342-xml.html
- Best Book on SOA Security
2008-04-12 16:37:16 Laura.Nguyen [Reply]
or maybe this one
http://www.instantz.net
- Best Book on SOA Security
- Best Book on SOA Security
- Best Book on SOA Security
2006-08-12 19:18:43 SOANetworkArchitect [Reply]
There are really no good books out there on SOA Security right now. The mentioned book from Manning Publishers is coming out in September. Thomas Erl will be adding a book on SOA Security in his Service-Oriented Computing Series early next year www.soabooks.com.
Also you can check out my blog: SOA Security Architect www.soasecurityarchitect.com
Regards,
Gary E. Smith
SOA Network Architect
SOA Networks
- Best Book on SOA Security
2007-01-26 04:36:36 johnvixen [Reply]
<div style='display:none'>Agreed (http://webservices.xml.com) </div>
- Best Book on SOA Security
- Best Book on SOA Security
- Locksmiths and Locks Install Rekeying Los Angeles 1-818-386-1022
2008-10-19 17:17:55 orellytos [Reply]
Locksmiths and Locks Los Angeles 1-818-386-1022
fast, reliable, professional locksmiths, superior workmanship & impeccable locksmith security services. Using only quality locks, tools and materials like: medeco lock, schlag locks, MUL T LOCK, schlag locks, Kwikset locks and baldwin locks, our standards of excellence provide you the most return for your home locksmith security investment. Over the years, we have developed a deep respect for the importance of individual expression in home and auto locksmith services. Right from the start of every locksmith project, we strive to fully understand and incorporate your individuality into every phase of planning, design and security locksmith Los Angeles
- Christmas Lights Installation Los Angeles 323-678-2704
2008-11-20 16:41:04 orellytos [Reply]
Christmas Lights Installation Los Angeles 323-678-2704
We offer the following Products and Services:
Christmas Lighting
Full service sales and installation departments
Custom pole-mounted banner sales and installation*
Large animated holiday displays
Custom holiday displays
Leasing and rental programs*
In house graphic arts department
Knowledgeable and helpful year round staff.
free estimate holiday lights installation
While Los Angeles may not have a traditional "White Christmas", it certainly does not leave you wanting of one. Diving into this city during the holidays always turns out to be a whirlwind of an occasion, and the glamour of Hollywood, combined with the wispy palms and beaches of Los Angeles serve as the backdrop of some of the most spectacular Christmas lights displays in the country! It'll make you wonder, who needs snow? The holidays in Los Angeles are more than complete without it!
Arguably one of the best lights displays in the country is at The Grove, a centrally located mall featuring a semi-outdoor arcade of shops and restaurants. It's not your typical box-type mall, and there's plenty of strolling in the chilly outdoor breezes, but the festive atmosphere more than makes up for it. Store hours are typically extended for the holidays, and there are lots of stalls and carts selling Christmas-themed treats and gadgets. There's a spectacular 60-some foot authentic Christmas tree-one of the largest you will ever see (they say it's even taller than the one at the Rockefeller center)-that lights up spectacularly at night. The entire home or business then seems to be encapsulated in a magical glow as lights blaze from every nook and cranny. There's also an electric sleigh that takes shoppers for a leisurely ride around the complex. The scene is sure to take your breath away!
1-310-925-1720
http://www.christmaslightinstallationlosangeles.blogspot ...
http://christmaslightinginstall.blogspot.com/
call us 310-925-1720
call 818-386-1022
- Carpet Cleaning Los Angeles 323-678-2704
2008-11-21 10:34:32 Movingcompany [Reply]
Carpet Cleaning Los Angeles 323-678-2704
all carpet cleaning upholstery area rug
steam clean or deep shampoo cleaning
- Locksmith Los Angeles 1-877-364-5264 24/7 Locksmiths
2008-12-16 12:47:58 services123 [Reply]
Locksmith Los Angeles 1-877-364-5264 24/7 Locksmiths
San Fernando Valley Locksmith 1-818-386-1022
Los Angeles Hollywood Locksmith 1-323-678-2704
West Los Angeles, Marina Del Rey, Culver City, Santa Monica, Beverly Hills Locksmith 1-310-925-1720
install, repair, professional, locksmiths, unlock, lockout, locked out, rekey, rekeying
Los Angeles Safe & Vault Sales and Installation For All Your Home & Business Needs | Doors installation wood, metal, Kalamein, and fire rated wood doors for both heavyweight commercial and standard residential needs. Door Closers Panic Bars Fire Exit Devices Floor or Head Check Bolts Door Frames Hinges Buzzer Systems Card Access Elevator Doors magnetic door locks, electric strikes, CCTV install Dvr Video Camera master key systems, CCTV and video surveillance, Alarm Systems, Keyless Entry Systems and Access Control Iron Works specializes in custom exterior and interior wrought iron design. We design and hand forge wrought iron entrance gates, driveway gates Child guard gates A/C cage gates Elevator doors Backyard gates Fire exit gates Custom design gates Storefront and Commercial Rolling Locksmith Blogs Locksmith Lockout Los Angeles Locksmith in Los Angeles
- 123 Carpet Cleaning Los Angeles 1-323-678-2704
2009-06-11 14:57:09 whats [Reply]
#1 Carpet Cleaning Los Angeles
call 1-323-678-2704 Steam or dry Cleaner - Carpet Steam or dry cleaning, Deep Shampoo Carpet Cleaning, Area Rugs cleaning, Mattress Cleaning, Upholstery furniture Cleaning, curtain cleaning, Green Organic Carpets Cleaning.
Los Angeles Carpet Cleaning Company Non-toxic Cleaning, Safeclean organic cleaning Los Angeles, California. Carpet cleaning Los Angeles,CA: We provide rug cleaning, upholstery cleaning, wood floor refinishing & maintenance, flood & water damage restoration, air duct cleaning and much more. LA Carpet Cleaning The Main Los Angeles Local Carpet Cleaners
- 123 Carpet Cleaning Los Angeles 1-323-678-2704
2009-06-11 14:57:11 whats [Reply]
#1 Carpet Cleaning Los Angeles
call 1-323-678-2704 Steam or dry Cleaner - Carpet Steam or dry cleaning, Deep Shampoo Carpet Cleaning, Area Rugs cleaning, Mattress Cleaning, Upholstery furniture Cleaning, curtain cleaning, Green Organic Carpets Cleaning.
Los Angeles Carpet Cleaning Company Non-toxic Cleaning, Safeclean organic cleaning Los Angeles, California. Carpet cleaning Los Angeles,CA: We provide rug cleaning, upholstery cleaning, wood floor refinishing & maintenance, flood & water damage restoration, air duct cleaning and much more. LA Carpet Cleaning The Main Los Angeles Local Carpet Cleaners
- Upholstery Cleaners Los Angeles 1-323-678-2704
2009-06-30 17:59:31 carpetcare [Reply]
Upholstery Cleaners Los Angeles 1-323-678-2704
Uphostered Furniture cleaning
Draperies cleaning
Window shades cleaning
Sofa sets cleaning
Leather Sets cleaning
Mattresses cleaning
Pet Furniture cleaning

