Migrating from SOAP Toolkit to Web services

Source: Internet
Author: User
Tags constant contains generator soap web services xmlns visual studio wsdl
Web Summary: How to access Web services from Visual Basic 6.0 and Visual Basic. NET, and how to convert existing SOAP applications to the. NET Platform.

Goal
Understanding the SOAP tools in Microsoft®visual studio®.net
Review using SOAP and Visual basic®6.0 to access com/com+ components
Accessing Web services from Visual Basic. NET
Migrating a SOAP Toolkit application to a WEB service
Prerequisite conditions
Learn what a WEB service is
Proficient and can access Visual Basic 6.0 and SOAP and know how to create a Activex®dll project
Familiarize yourself with the basics of Visual Studio. NET
Web Services, SOAP, and your tools
Web services provide a feature that can be accessed over the Internet by invoking the Web service and getting the results returned. The new feature of WEB services is that you can now connect to services on the world's largest network internet. However, as a Visual Basic programmer, WEB services handle cumbersome Internet transactions for you.

In this article, you will learn how to use visual Studio. NET to access Web services, review the process of creating Web Services using Visual Basic 6.0 and SOAP Toolkit 2.0, and learn how to transform existing SOAP Toolkit Application to use WEB services in the. NET framework.

The WEB services used in this article have a very simple function createcustomer. It accepts the customer's name and returns the customer identifier. However, we don't discuss the functionality of Web services here so that you can focus on how to create and access Web services using Visual Basic 6.0 or Visual Basic. NET.

Visual Basic and SOAP
The user communicates with the WEB service by sending and receiving SOAP documents. In Visual Basic 6.0, there are two ways to create a SOAP document:

Combining documents with connection strings
Using the SoapClient in SOAP Toolkit 2.0
SoapClient not only creates a SOAP document to communicate with a Web service, but also sends the document to a Web service for processing.

On the Web service side of the transport, a SOAP listener is required to capture and process the documents sent by the client. Soap Toolkit 2.0 includes SoapServer, which can be used in listening applications to process SOAP documents. Listeners are individually created applications that are independent of the components that implement WEB services.

With Visual Studio. NET, you can simplify the creation and access of WEB services. In Visual Studio. NET, creating a Web service does not require the construction of a separate listening application. When you access a Web service, it automatically creates a proxy for you, so that you can use a Web service just as you would access any other object.

Web Service Description Tool
Web Services Description Language (WSDL) is an XML language that is designed specifically to describe Web services. As part of the process of making WEB services an open standard, WSDL has been submitted to the consortium with SOAP. The WSDL description of the service can contain Wsdlspec TModel, which provides the service with all the information it needs to create and send a SOAP document. The following is an example of a wsdlspec TModel file that supports the CreateCustomer function:

<?xml version= ' 1.0 ' encoding= ' UTF-8 '?>
<!--generated 06/25/01 by Microsoft SOAP Toolkit WSDL
File generator, Version 1.00.623.1-->
<definitions name = ' Cust '
targetnamespace = ' http://tempuri.org/wsdl/'
xmlns:wsdlns= ' http://tempuri.org/wsdl/'
xmlns:typens= ' Http://tempuri.org/type '
xmlns:soap= ' http://schemas.xmlsoap.org/wsdl/soap/'
Xmlns:xsd= ' Http://www.w3.org/2001/XMLSchema '
xmlns:stk=
' Http://schemas.microsoft.com/soap-toolkit/wsdl-extension '
xmlns= ' http://schemas.xmlsoap.org/wsdl/' >
<types>
<schema targetnamespace= ' Http://tempuri.org/type '
xmlns= ' Http://www.w3.org/2001/XMLSchema '
Xmlns:soap-enc=
' http://schemas.xmlsoap.org/soap/encoding/'
Xmlns:wsdl= ' http://schemas.xmlsoap.org/wsdl/'
elementformdefault= ' qualified ' >
</schema>
</types>
<message name= ' Custservices.createcustomer ' >
<part name= ' A ' type= ' xsd:string '/>
<part name= ' last ' type= ' xsd:string '/>
</message>
<message name= ' Custservices.createcustomerresponse ' >
<part name= ' result ' type= ' xsd:string '/>
</message>
<porttype name= ' Custservicessoapport ' >
<operation name= ' CreateCustomer '
Parameterorder= ' The last ' >
<input message=
' Wsdlns:Custservices.createCustomer '/>
<output
message= ' Wsdlns:Custservices.createCustomerResponse '/>
</operation>
</portType>
<binding name= ' custservicessoapbinding '
Type= ' Wsdlns:custservicessoapport ' >
<stk:binding preferredencoding= ' UTF-8 '/>
<soap:binding style= ' RPC '
transport= ' Http://schemas.xmlsoap.org/soap/http '/>
<operation name= ' Add ' >
<soap:operation soapaction=
' Http://tempuri.org/action/Custservices.Add '/>
<input>
<soap:body use= ' encoded '
Namespace= ' http://tempuri.org/message/'
encodingstyle=
' http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use= ' encoded '
Namespace= ' http://tempuri.org/message/'
encodingstyle=
' http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name= ' Cust ' >
<port name= ' Custservicessoapport '
binding= ' wsdlns:custservicessoapbinding ' >
<soap:address
location= ' Http://localhost/customer/cust.ASP '/>
</port>
</service>
</definitions>

The <service> tag at the end of the Wsdlspec TModel specifies the SOAP listener to which the request will be sent, in this case, to the Http://localhost/cust/cust.asp page. The previous section of this file describes the messages that the service can use.

Note: The namespace tempuri.org used in the SOAP document is a temporary namespace that is used only at development time (temporary URI). Before this service is committed to the product, you should modify the WSDL file so that it has a unique URI (for example, the URL of your company's Web site).
Both the SOAP Toolkit object and the Visual Studio. NET IDE Read the WSDL file. SoapClient uses the information in the WSDL file to make it a proxy for the Web service. Visual Studio. NET uses the same information to generate proxy classes for WEB services. Therefore, you can do the following:

Invoke the methods of the WEB service as if they were methods of these proxies.
Before sending the message, verify the call based on the WSDL description of the Web service.
Interacts with the agent without having to be familiar with the contents of the WSDL file or the SOAP document to be generated.
Figure 1 shows the relationships among the components, including WEB service Meta language (WSML) files. Only Visual Basic 6.0 requires this file, and it is described in its walkthrough.




Figure 1:web Services and client diagrams

In soap, soap Toolkit and the Visual Studio. NET IDE perform similar functions. The difference is that the SOAP Toolkit object does not provide all the support the Visual Basic developer needs. In Figure 2, you can see intellisense® support (Visual Basic programmers think this kind of support is necessary). The IntelliSense drop-down list automatically displays the CreateCustomer method for Customerservices COM objects.




Figure 2:com/dcom/com+ IntelliSense support for objects

In Figure 3, you can see the IntelliSense support that SoapClient provides for the Web service. All SoapClient methods are listed but do not show the methods (that is, CreateCustomer) owned by the service that will soapclient as a proxy.




Figure 3: IntelliSense support with SoapClient

If you use Visual Studio. NET, the proxy class generated by the IDE can better represent WEB services than soapclient. In Figure 4, you can see IntelliSense support for accessing the WEB service. The CreateCustomer method is one of the methods owned by the object that interacts with the WEB service.




Figure 4:visual IntelliSense support for WEB services in Studio. NET

SOAP Toolkit 2.0 Overview
This section briefly reviews the process of creating Web services described in the previous section of Web Services, SOAP, and your tools.

Creating and accessing Web services using SOAP Toolkit
In Visual Basic 6.0, create a new Visual basic ActiveX DLL project named Custcp for the Web service and a class module named Customerservices and its code:
Public Function CreateCustomer (ByVal as String, _
ByVal last As String) as String

CreateCustomer = "A" & CStr (Len (A)) & _
CStr (Len (last))
End Function

Use the SOAP Toolkit WSDL Wizard to generate the WSDL and WSML files (WSML file contains the information that SoapServer is used to map from the Web service to the ActiveX COM object).
Create a SOAP listener as an ASP page that uses soapserver:
<%@ Language=vbscript%>
<%option Explicit

Dim SS
Dim WSDL
Dim WSML

Response.ContentType = "Text/xml"

WSDL = Server.MapPath ("cust.wsdl")
WSML = Server.MapPath ("CUST.WSML")

Set ss = Server.CreateObject ("Mssoap.") SoapServer ")
Ss. Init WSDL, WSML
Ss. Soapinvoke Request, Response, ""%>

Create a client to invoke a WEB service that uses soapclient:
Private Sub Cmdcreate_click ()
Dim SC as Mssoaplib.soapclient

Set sc = New soapclient
Sc.mssoapinit "HTTP://VOGEL2/CUST/CUST.WSDL"
Me.txtCustId.text = _
Sc.createcustomer (Me.txtFirstName.text, _
Me.txtLastName.text)
End Sub

Visual Basic. NET Walkthrough
In this section, you will learn how to do the following:

Create a Web service in Visual Studio. NET.
Access Web services from Visual Basic. NET applications.
When you build a Web service in Visual Studio. NET, a "discovery file" is automatically generated for the Web service. Discovery files are used to add Web service references to other Visual Studio. NET applications, including WSDL descriptions.

Note: For Visual Basic and C # projects, the file type of the found file is. vsdisco; for the C project, it is. Disco.
Creating a Web service in Visual Studio. NET
On the File menu, select New to display the New Project dialog box, as shown in Figure 5.


Figure 5:visual Studio. NET New Project Dialog box

In the Visual Basic Projects (Project) section, select the ASP.net Web service.
In the Name box, give the project name (Migratetodotnetservice).
Enter the Web site URL (localhost/customer) for the Web service.
Click OK to create the project. By default, the project contains a module named Service1.asmx.
Right-click the Service1.asmx module and select View code from the menu.
Add this code to the public Class Service1 statement at the top of the module, as follows:
<webservice (namespace:= "http://phvis.com/customer/", _
description:= "Customer Management") _
Public Class Service1

Copy the CreateCustomer function from the Visual Basic 6.0 example, but add the <WebMethod> property to the function declaration as follows:
<webmethod (description:= _
"Pass name, return ID value") > _
Public Function CreateCustomer (_
ByVal as String, _
ByVal last As String) as String

You can convert Visual Basic 6.0 code to Visual Basic. NET syntax if you only need to change one place. Use the return substitution function for createcustomer =, as follows:
Return "A" & CStr (Len (A)) & _
CStr (Len (last))
End Function

On the Build menu, select Build to create the Web service. Check for errors in the build process in the Output window. As part of the build, the application's discovery files are also generated.
Creating a Client
Without creating a. NET client, a Visual Basic 6.0 application created with SOAP Toolkit can access the. NET Web service. The following steps show how to create a. NET Client for a Web service (regardless of whether the Web service was written in Visual Basic 6.0 or Visual Basic. NET):

On the File menu, select New (New), and then select Project to display the Add Project dialog box.
In the Visual Basic Projects (Project) section, select Windows Application (Windows applications).
Give the project name (migratetowebclient) in the Name box, and click OK to create the project.
In Solution Explorer (Solution Explorer), right-click the project and select Add Web Reference (Add Web Reference). The Add Web Reference (Add Web Reference) dialog box appears, as shown in Figure 6.


Figure 6:add Web Reference (Add Web Reference) dialog box

In the Address box, enter the URL of the. vsdisco file for the Web service project. For example, Http://localserver/customers/MigratetoNetService.vsdisco. Click the arrow at the end of the Address box to select the reference.
Note: You can also obtain the URL of the. vsdisco file for a WEB service project by dragging the. vsdisco file from Solution Explorer (Solution Explorer) to the code module. This adds the URL of the file to the code module. Then, cut the URL from the module and paste it into the Address box in the Add Web Reference dialog box.
Click the Add Reference (Add Reference) button to return to the item. A reference to the Web service is displayed in Solution Explorer (Solution Explorer), as shown in Figure 7.


Figure 7: Visual Basic Windows Application containing a reference to a WEB service

Add a text box named txtFirstName and Txtlastname to the form that holds the customer's name and adds a button to the code that invokes the Web service.
Add code to declare a variable that refers to a proxy class that handles WEB services (the default name for the proxy class consists of the server name and service name):
Private Sub Cmdcreate_click ()
Dim cc as Localhost.service1

Add code to instantiate the proxy class and invoke the Web service method:
Set cc = New Localhost.service1
Me.txtCustId.text = _
Cc.createcustomer (Me.txtFirstName.Text, _
Me.txtLastName.Text)
End Sub

Press F5 to run the client and access the WEB service.
Converting from SOAP Toolkit to Visual Studio. NET
Applications built using SOAP Toolkit or. NET Web Services conform to the SOAP specification. When using a SOAP based application, the connection between the client and the WEB service is defined by the WSDL file. Web services built with. NET can use Web services generated by SOAP Toolkit, and vice versa. This allows you to progressively migrate from SOAP Toolkit to. NET by storing the WSDL definition of the service constant. For example, clients accessing a Web service can continue to use the SOAP Toolkit soapclient while the Web service is transitioning to. NET.

The easiest way to store a WSDL file for a Web service constant is to copy the Visual Basic 6.0 code into the ASMX module of the Web service. After replication is complete, you must add the <WebService> and <WebMethod> properties to the class module to create a. NET Web service. You will then need to convert the Visual Basic 6.0 code to. NET syntax, as described in MSDN and other articles in this series. If you want to create a new. NET version of the Web service, you can use the SOAP Toolkit version of the WSDL file to generate the basic code for the Web service.

On the client side, different client applications that access the Web service can be converted from SOAP Toolkit to. NET separately. Because of the interoperability provided by the SOAP specification, even if multiple. NET versions are generated by one client, no problem arises. To convert from SOAP Toolkit to Visual Studio. NET within the client, you must replace the reference to soapclient with a reference to the WEB service proxy.

Summary
You've learned how to access Web services from Visual Basic 6.0 and Visual Basic. NET. You also learned what you need to do to convert an existing SOAP application to a. NET platform.

The key to remember is the following three points:

A WSDL file is used to describe a SOAP document that can be sent to a WEB service. In Visual Basic 6.0, you can create this file using the WSDL generator of the SOAP Toolkit, which is automatically generated for you in Visual Studio. NET.
When you create a Web service in Visual Basic 6.0, you need a Microsoft WSML file and a separate ASP listener page, which is not required when you create a asp.net Web service in Visual Studio. NET.
You can mix clients and services at will without having to consider the platform. You can use SoapClient to invoke the Visual Basic. NET service from a Visual Basic 6.0 client or ASP page, and your Visual Basic 6.0 Web service can use soapserver processing from A request from the Visual Studio. NET client.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.