10.4 Compatibility

only for RuBoard

Document/literal and RPC-encoded SOAP were already briefly discussed. The terms themselves mean that the SOAP body can be either RPC-based or Document-based, and the method parameters described within the SOAP body are either Literal or Encoded .

Literal maps method parameters to an XSD schema for each parameter. Each parameter has an element that contains a literal string describing type. These types are mapped to the xsd namespace defined in the SOAP envelope:

 <!-- Used by ASP.NET Web services -->     <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi=   http://www.w3.org/2001/XMLSchema-instance    xmlns:xsd=http://www.w3.org/2001/XMLSchema  xmlns:soap=   http://schemas.xmlsoap.org/soap/envelope/   >   <soap:Body>     <IsValid xmlns="http://192.168.1.100/">       <City>string</City>       <Zip>string</Zip>     </IsValid>   </soap:Body> </soap:Envelope> 

Encoded means that the parameters are encoded as described in Section 5 of the SOAP specification. [2] A complex type is defined for each parameter:

[2] This specification can be found at http://www.w3c.org.

 <!-- Used by remoting and other non-.NET SOAP clients -->     <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi=   http://www.w3.org/2001/XMLSchema-instance   xmlns:xsd=   http://www.w3.org/2001/XMLSchema   xmlns:soapenc=   http://schemas.xmlsoap.org/soap/encoding/   xmlns:tns=   http://192.168.1.100/   xmlns:types=   http://192.168.1.100/encodedTypes   xmlns:soap=   http://schemas.xmlsoap.org/soap/envelope/   > <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <tns:IsValidRPC>     <City xsi:type="xsd:string">string</City>     <Zip xsi:type="xsd:string">string</Zip>   </tns:IsValidRPC> </soap:Body> </soap:Envelope> 

While Document can use Literal or Encoded parameters, RPC-style SOAP is limited to encoded parameters. To create Document/encoded SOAP, use the SoapDocumentMethod attribute on the web method:

 <WebMethod( ), SoapDocumentMethod(Use:=SoapBindingUse.Encoded)> _   Public Function IsValidEncoded(ByVal City As String, ByVal Zip As String) As  Boolean 

Example 10-6 contains a listing of ZipService that provides methods using all three styles.

Example 10-6. ZipService encoding test
 'vbc /t:library /r:System.dll  '/r:System.Web.Services.dll ZipService.vb     Imports System Imports System.Web.Services Imports System.Web.Services.Description Imports System.Web.Services.Protocols     'Inherits from MarshalByRefObject for .NET Remoting     <WebService(Namespace:="http://192.168.1.100/")> _ Public Class ZipService : Inherits MarshalByRefObject       <WebMethod( )> _   Public Function IsValid(ByVal City As String, _                           ByVal Zip As String) As Boolean     Return True   End Function       <WebMethod( ), SoapRpcMethod( )> _   Public Function IsValidRPC(ByVal City As String, _                              ByVal Zip As String) As Boolean     Return True   End Function       <WebMethod( ), SoapDocumentMethod(Use:=SoapBindingUse.Encoded)> _   Public Function IsValidEncoded(ByVal City As String, _                                  ByVal Zip As String) As Boolean     Return True   End Function     End Class 

The service description pages generated by ASP.NET allow inspection of the SOAP for each method.

Even if using a web service from remoting is not desired, it is still a good idea to use the SoapRpcMethod attribute for interoperability. There are quite a few SOAP clients out there that expect RPC-encoded SOAP. Supplying the attribute doesn't hurt because ASP.NET supports both encoding styles.

Also, a few SOAP toolkits do not know how to deal with the HTTP/Post and HTTP/Get bindings generated by ASP.NET. For these SOAP clients to use the web service, you might need to disable these bindings by placing the following entries in Web.config :

 <system.web>   <webServices>     <protocols>       <remove name="HttpPost" />       <remove name="HttpGet" />     </protocols>   </webServices> </system.web> 

There is an upside and a downside to doing this. While the web service is now potentially available to many more SOAP clients, ASP.NET uses the HTTP/Get to create the testing form for the web method. As shown in Figure 10-5, it will no longer be available when the bindings are removed.

Figure 10-5. Web method test is no longer available when HTTP bindings are removed
figs/oop_1005.gif
only for RuBoard


Object-Oriented Programming with Visual Basic. Net
Object-Oriented Programming with Visual Basic .NET
ISBN: 0596001460
EAN: 2147483647
Year: 2001
Pages: 112
Authors: J.P. Hamilton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net