Verifying Username and Password Credentials

The one thing we haven't discussed is how the authentication details are validated by the Web service. If you're using X509 certificates as the credentials, no checking is done by the Security input filter to validate the certificate you passed another nail in the coffin of using X509 certificates for authentication If you're using username and password security credentials, once you receive a lt wsse UsernameToken gt , you must verify that the username and password are correct. If you don't...

Setting XML Elements with [XmlElement

TheSystem.Xml serializer treats all public fields and properties of classes involved in Web methods in exactly the same way it turns them into elements in your request and response messages and gives each element the same name as the field or property. In our TagService project, the serializer takes our request class public string ReqElement1 public subclass ReqElement2 public string ReqAttribute1 and presents us with the following schema lt s complexType name requestClass gt lt s sequence gt...

Setting XML Attributes with [XmlAttribute

If you'd prefer that a class member a field or a property be represented as an attribute of the element representing the class, you can inform the serializer by tagging the member with an XmlAttribute attribute. For example, in our TagService example the requestClass class has a field named reqAttribute1 that is being turned into an element by the serializer and that we'd prefer to be an attribute. If we tag the class like so public string ReqElement1 public subclass ReqElement2 public string...

Wrapping It All Up with [SoapDocumentMethod

Last but not least, we come to the Web methods themselves and how they influence the service schema. As you'll recall from our look at XmlRoot , the serializer uses a class method's signature to derive a wrapper element for request and response messages that encapsulates elements representing the method's parameters and return values, respectively. So, by default, the request message takes this shape lt soap envelope gt lt soap body gt lt methodname gt lt methodname gt lt soap body gt and the...

Working with DocumentLiteral Services

Unless told otherwise, .NET assumes that every Web service and method is of the document literal variety. However, if you want to make this explicit, you have two options Add a SoapDocumentService attribute to your Web service class. Any Web method in the class will be serialized as document literal by default. Add a SoapDocumentMethod attribute to your class method in addition to the WebMethod attribute. Both attributes can be found in the System.Web.Services.Protocols namespace, so don't...

A Simple Example in Web Matrix

For those of you who would rather not work with raw text but who don't want a copy of Visual Studio .NET, the Web Matrix project, available for download at http www.asp.net , is well worth looking into. A cut-down version of Visual Studio .NET purely for ASP.NET and therefore Web service development, Web Matrix crosses the feel and RAD capabilities of a proper IDE with the absolute control of a text editor. Like Visual Studio .NET, it also has its own Web service wizard. Start Web Matrix, and...

A Basic Windows Forms Client

For our Windows Forms client, we'll create a client to consume the two example Web methods that we created in the p extension of our media player example. Our completed media player won't actually play any CDs although it wouldn't b application to play a CD . Instead, it will simply identify the CD placed in the drive and return information about the CD lt from both the freedb.org database which contains only album titles and track listings and from our own database. In the previous chapter, we...

Mapping a Handler to a File Extension

If you need to handle the processing of files with a certain file extension, you must first compile your class into an assembly and then place that assembly in either the GAC or, preferably, your Web application's bin directory. You cannot associate a class inside a handler or code-behind file to a file extension. In this example, we'll associate requests for .wbsvc files with the following class, which has been compiled using Visual Studio .NET you can also compile it from the command line...

IHttpHandlerFactory

As the name IHttpHandlerFactory suggests, a class that implements this interface is not a handler in itself but offers an alternative and arguably more elegant way to deal with requests into a Web service. Thus far, we've developed a handler that discerns how the service is being requested and calls a method to give an appropriate response. A handler factory class discerns how the service is being requested and creates a handler to give the appropriate response a similar tactic but with...

Capturing SOAP Messages

The SOAP messages are transmitted between the client and the Web service, so if you want to capture and view them choose between a couple of approaches. One is to use the SOAP extensions to create a log and write the SOAP mess log. We'll cover SOAP extensions in Chapter 10. The second approach is to use the SOAP trace utility provided in the SOAP Toolkit whose latest version is 3.0 . This toolkit allows developers to add XML Web service functionality to their COM applications, but it also...

asmx File Discovery

In addition to the two physical discovery documents that you can create for static or dynamic discovery, the .asmx files that contain your Web services can also generate an .asmx discovery file. In much the same way that you can interrogate an .asmx file to provide the correct WSDL for the Web service by using the wsdl query string, you can use the disco query string to force an .asmx file to give you the discovery document for itself. The RecordFinder Web service that we mentioned in the...

The UDDI Category System

It is perfectly possible to search for a Web service by name, but this is not always practical. If you have a simple Web service that adds two numbers, it might be called AddTwoNumbers, SumNumbers, NumberAdd, or one of other names that you can no doubt think of. It would be better in this case to classify the Web service by category. Adding it to a Mathematics category would be a start, and adding it to an Addition subcategory would be even better. Users looking for the Web service can then...

Creating Choices with [XmlElement and [XmlChoiceIdentifier

Asyou saw when we discussed writing schemas explicitly, complex types with complex content can be derived by using lt sequence gt , lt choice gt , or lt all gt elements. Thus far, you've seen the serializer produce only sequences of elements. It is possible to create a lt choice gt , which we'll see now, but there is no way to imply lt all gt . In our TagService example, suppose we want to distinguish between soloists and bands. Rather than create an extra service for each scenario, we can just...