Simple Web Service That Demonstrates the Server Interface Feature
To use the ServerInterface feature, you have two options:
- (1) Run wsdl.exe using the /serverInterface switch (or /si for short) with a wsdl file. The output will
be a code file that contains an interface for each wsdl binding.
- (2) Write the interface(s) yourself and apply [WebServiceBindingAttribute] on the interface(s),
and [WebMethodAttribute] on each Web method in the interface(s).
Here is an example of how to use option (1) from the command line:
wsdl.exe /si ServerInterfaceSample.wsdl
The Web service in this sample was written using Option (2). The interface looks like this:
[WebServiceBinding(Name="ReportDateTime", Namespace="Microsoft.Samples.XmlMessaging.WebServices")]
public interface IReportDateTime
{
[WebMethod]
DateTime getCurrentDateTime();
}
C#
The implementation looks like this:
[WebService(Namespace="Microsoft.Samples.XmlMessaging.WebServices")]
public class ServerInterfaceService : IReportDateTime
{
public DateTime getCurrentDateTime()
{
//Web method implementation here
}
}
C#
Regardless of which you option you use, you will need to implement the interface(s) in your service code.
The benefit of this feature is that implementation code is kept separate from the contract code (as defined by the interface).
If you change the wsdl and then regenerate your interface(s), you will not lose any of the implementation code.
To follow recommended design guidelines, you should not put any code in the implementation that changes the wsdl contract.
Likewise, you should not alter the interfaces with code that affects the run-time behavior.
Contract and implementation details remain separate.
NOTE: This feature deprecates the use of /server with wsdl.exe.
C# Sample Caption
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|