Home   Cover Cover Cover Cover
 

SOAP Encoding


From Section 7.3.1 of the book

The attribute [SoapRpcFormat] extends the message format for web services with the format rpc/encoded. Without this attribute the encoding is document/literal. The SOAP encoding requires us to import the namespace System.Web.Services.Protocols. Methods must have unique names, therefore GetTime cannot be overloaded so our new method must be named GetTime2.

TimeService.asmx
<%@ WebService Language="C#" Class="TimeService" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;

[SoapRpcService] // this web service uses the message format soap/encoded
public class TimeService : WebService {
  
  [WebMethod(Description="Returns the current time")]
  public string GetTime() { 
    return System.DateTime.Now.ToLongTimeString(); 
  }
  
  [WebMethod(Description="Returns the current server time in a long or short format")]
  public string GetTime2(bool shortForm) {
    if (shortForm) return DateTime.Now.ToShortTimeString();
    return this.GetTime();
  }
}

If you copy this code to a file TimeService.asmx in a virtual directory of your local machine you can open it with Internet Explorer and get a test page that allows you to invoke the methods GetTime and GetTime2.

Alternatively, you can test your web service also with Webservice Studio.