These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

ASP.NET Web Services QuickStart Tutorial

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()>  _
	Function getCurrentDateTime() As DateTime

End Interface 'IReportDateTime
VB


The implementation looks like this:

		
<WebService(Namespace:="Microsoft.Samples.XmlMessaging.WebServices")>  _
Public Class ServerInterfaceService
	Implements IReportDateTime

	Public Function getCurrentDateTime() As DateTime Implements IReportDateTime.getCurrentDateTime	
		'Web method implementation here
	End Function 'getCurrentDateTime

End Class 'ServerInterfaceService
VB


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.
VB Sample Caption
Run Sample View Source



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.