Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ServiceDescriptionImporter Class

Exposes a means of generating client proxy classes for XML Web services.

System.Object
  System.Web.Services.Description.ServiceDescriptionImporter

Namespace:  System.Web.Services.Description
Assembly:  System.Web.Services (in System.Web.Services.dll)

'Declaration
<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
<PermissionSetAttribute(SecurityAction.LinkDemand, Name := "FullTrust")> _
Public Class ServiceDescriptionImporter

The ServiceDescriptionImporter type exposes the following members.

  NameDescription
Public methodServiceDescriptionImporterInitializes a new instance of the ServiceDescriptionImporter class.
Top

  NameDescription
Public propertyCodeGenerationOptionsGets or sets various options for code generation.
Public propertyCodeGeneratorGets or sets the code generator used by the service description importer.
Public propertyProtocolNameGets or sets the protocol used to access the described XML Web services.
Public propertySchemasGets the XmlSchemas used by the ServiceDescriptions property.
Public propertyServiceDescriptionsGets the collection of ServiceDescription instances to be imported.
Public propertyStyleGets or sets a value that determines the style of code (client or server) that is generated when the ServiceDescriptions values are imported.
Top

  NameDescription
Public methodAddServiceDescriptionAdds the specified ServiceDescription to the collection of ServiceDescriptions values to be imported.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberGenerateWebReferencesCompiles a collection of Web references to produce a client proxy or a server stub.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodImportImports the specified ServiceDescriptions values, that generates code as specified by the Style property.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The interface to an XML Web service is typically described by a Web Services Description Language (WSDL) file. For example, to obtain a WSDL description of a Web service using ASP.NET exposed at http://localhost/service.asmx, simply navigate to http://localhost/service.asmx?WSDL.

The ServiceDescriptionImporter class allows you to easily import the information contained in a WSDL description into a System.CodeDom.CodeCompileUnit object. By adjusting the value of the Style parameter, you can instruct a ServiceDescriptionImporter instance either to generate a client proxy class that provides the functionality of the Web service by transparently calling it or to generate an abstract class that encapsulates the functionality of the Web service without implementing it.

The code in the resulting CodeCompileUnit object can then either be called directly or exported in the language of your choice.

The following example illustrates the use of the ServiceDescriptionImporter class to generate proxy client code that calls an XML Web service described by a WSDL file.


Imports System
Imports System.Web.Services.Description
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports System.Security.Permissions

Public Class Import

	Public Shared Sub Main()
		Run()
	End Sub

	<PermissionSetAttribute(SecurityAction.Demand, Name := "Full Trust")>
	Public Shared Sub Run()
	' Get a WSDL file describing a service.
	Dim description As ServiceDescription = ServiceDescription.Read("service.wsdl")

	' Initialize a service description importer.
	Dim importer As New ServiceDescriptionImporter()
	importer.ProtocolName = "Soap12" ' Use SOAP 1.2.
	importer.AddServiceDescription(description,Nothing,Nothing)

	' Report on the service descriptions.
	Console.WriteLine("Importing {0} service descriptions with {1} associated schemas.", importer.ServiceDescriptions.Count, importer.Schemas.Count)

	' Generate a proxy client.
	importer.Style = ServiceDescriptionImportStyle.Client

	' Generate properties to represent primitive values.
	importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties

	' Initialize a Code-DOM tree into which we will import the service.
	Dim nmspace As New CodeNamespace()
	Dim unit As New CodeCompileUnit()
	unit.Namespaces.Add(nmspace)

	' Import the service into the Code-DOM tree. This creates proxy code
	' that uses the service.
	Dim warning As ServiceDescriptionImportWarnings = importer.Import(nmspace,unit)

	If warning = 0 Then
		' Generate and print the proxy code in VB.
		Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("CSharp")
		provider.GenerateCodeFromCompileUnit(unit, Console.Out, New CodeGeneratorOptions())
	Else
		' Print an error message.
		Console.WriteLine(warning)
	End If
	End Sub


End Class


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

Show:
© 2017 Microsoft