Last Updated: 2001
SOAP - Simple Object Access Protocol
Explicit serialisation protocol used to exchange information between client
& server. Uses HTTP with XML description.
WSDL - Web Service Description Language
An XML document that gives the location and describes the contract (i.e.
what methods / interfaces) the described service supports
DISCO - Discovery
An XML document that gives the URI of one or more services provided by the
server
UDDI - Universal Description Discovery & Integration
Directory of services
The difference between DISCO and UDDI is that to use DISCO you need the know the URL of the server supporting the desired service. To use UDDI you need to know the location of the URL "Yellow Pages" book and have a description of the desired service you require.
In theory, the sequence goes something like this:
You need a particularly service, say the verification of a VISA number.
You use UDDI to get a DISCO or WSDL document for a suitable service from a "Yellow Pages" site - perhaps uses additional criteria such as cost to narrow the field.
You if have a DISCO you use that to identify the server to request the WSDL document for the service.
Using the information contained in the WSDL you invoke the right service using the described protocols and parameters, and get the result in the described format..
In practice, unless the system is dynamic, steps 1 to 3 only occurs during design time
.
Create a asmx/asmx.cs file set. A single .asmx file set can hold define services.
For each service create a new public class derived from System.Web.Services.WebService
For each operation the service supports, add a public method
with an attribute of WebMethod
Example:
using System;
using System.Web;
using System.Web.Services;
namespace WebService2 {
public
class Service1 :
System.Web.Services.WebService {
[WebMethod]
public
int Add(int
a, int b) {
return a+b;
}
[WebMethod(MessageName="Add3")]
public
int Add(int
a, int b,
int c) {
return a+b+c;
}
[WebMethod]
public
void AddByRef(int
a, int b,
ref
int c) {
c=a+b;
}
[WebMethod]
public
int AddClass(myClass a,
myClass b) {
return a.iNum + b.iNum;
}
}
public
class myClass {
public
int iNum;
}
}
Notes:
If its serialisable, it can be used as a parameter. Note the ref parameter in the AddByRef operation and the classes in the AddClass operation.
If you write the code through the VS interface additional code will be generated to support the designer. This allows the "dropping" or other components onto the web service.
Everything available to a normal web application is available here, such as Application["SomeRef"] caching. I wouldn't try UI if I were you though.
Web Services do not, by default, support session state. To enable session state (and thus be able to use things like the Session object) the EnableState attribute needs to be specified in the WebMethod attribute, i.e. [WebMethod(EnableSession=true)]. The application object is not a session object, so is available irrespective of this setting.
To get a user-friendly interpretation of the WSDL file look at
the service through a browser, e.g.
http://localhost/WebService2/Service1.asmx (This can be turned off)
Through HTTP GET,e.g.
http://localhost/WebService2/Service1.asmx/Add?a=2&b=2 (if a parameter is
an object, HTTP GET cannot be used)
Through SOAP. Add a Web Reference to the calling project, then
create an object of the right type and call the operation on it:
localhost.Service1 oS1 =
new localhost.Service1();
oS1.Add(1,2);
Note:
No Using statement is required.
"localhost" is a proxy object so named because that was part of the URL to the disco file. We could easily have created it with a different name and their are command line tools to create the proxy automatically if you want to do it on the fly (or outside of the VS IDE). The proxy object can support multiple services (don't know if those services can reside on different servers though).
By default, every property is a tag, for example:
myClass {
int a=2;
int b=4;
}
is written in the SOAP message as:
<myClass>
<a>int</a>
<b>int</b>
</myClass>
Use the [XMLElement()] attribute to make these attributes of the tags, for
example :
using System.Xml.Serialization;
....
myClass {
[XMLElement()]
int a=2;
[XMLElement()]
int b=4;
}
becomes:
<myClass a=2 b=4 />
Note: Doesn't work when I try it! Compiles fine, but SOAP message format is
unchanged.