用LabView 访问远程 .NET Web Services 调用本地的Web Services,可是在另一台机器上的Web Services怎样调用
一样的过程啊,在.Net Web Service Browser里输入Web service所在服务器的地址,不管是本地还是远程的,下面的过程是一样的。另外,实例化一个web service对象后,你还可以修改它的url属性,指向任何一台服务器上的web service. (当然前提是那台服务器上有对应的服务)
Building a Web Service-Based Application in LabVIEW 7.0
Print this age
Web services have emerged as the next generation of Web-based technology for exchanging information between applications across the Internet. This document describes how
to incorporate Web service components into LabVIEW 7.0 or later applications by leveraging Microsoft .NET
technology.
Table of Contents:
What are Web Services?
Communicating with Web Services
Finding a Web Service
Leveraging .NET
Creating a .NET Assembly Wrapper
.NET Web Service Browser
Creating a Web Service-Based Application
What are Web Services?
Microsoft defines a Web service as a programmable application logic accessible using standard Internet protocols.
Web services represent black-box functionality that you can reuse across the Internet without any knowledge about how they are implemented.
Figure 1. Using Web Services Web pages are served by Web servers for human consumption through Web browsers. Web services are intended
to be consumed by applications. A Web service is similar to a set of functions exported to the Internet through a
Web server.
Web services are gaining popularity due to the several benefits they offer:
Code Reuse -- Building applications is simplified when you use off-the-shelf Web service components.
Platform Independence -- Because you access Web services using standard Internet technologies, the consumers of a Web service can be
on any platform.
Language Independence -- For the same reason as above, you can implement the consumers in any language, and you do not need to know
the implementation details of the Web service to access it.
Distributed Computing -- You can use Web service components to easily build distributed applications that span firewalls.
With industry leaders like Microsoft and IBM supporting Web services, you might see a large increase in the number
of Web services available in the near future.
Communicating with Web Services
You access Web services using popular Web protocols, data formats, and message formats, such as Hypertext
Transfer rotocol (HTTP), Extensible Markup Language (XML), and Simple Object Access rotocol (SOAP). You
use HTTP to send and receive messages between the Web service and the consumer of the service. You use XML
to describe and represent the data exchanged. SOAP defines the messages and their bindings to HTTP. Using the
SOAP protocol, you can send and receive messages that are well understood by both the Web service and the
consumer.
However, the consumer needs to know which messages to send and receive. A document describing the interface
to the Web service is useful in this case. Web Services Description Language (WSDL) is an XML-based contract language jointly developed by Microsoft and IBM. A Web service publishes its interface in WSDL at
a specific URL. A consumer then can read the WSDL specification from the URL and create SOAP messages to
communicate with the Web Service.
Finding a Web Service
Much like a local vendor advertises in the phone book, vendors of Web services publish their services in well-known Web directories. Searching in Google for "Web Services Directory" yields several results. Common directories
also are linked below. These directories list Web services by categories and allow you to search for Web services
using keywords. After you find a Web service of interest, you must find its WSDL specification. You typically find a
link to the WSDL specification in the description of the Web service in a directory.
See Also:
Google Directory - Computers: Programming: Internet: Web Services
XMethods
SalCentral
Microsoft UDDI Business Registry
Leveraging .NET
Communicating with a Web service using SOAP messages is similar to writing code in an assembly language. It is
efficient but hard to write, debug, and maintain. You can simplify the task greatly with a higher level of abstraction
using Microsoft's .NET technology.
Microsoft .NET provides a structured class-based interface with properties and methods. The LabVIEW .NET interface is similar to the interface for the ActiveX
client.
You introduce an abstraction layer between a VI and the Web service. This layer does the work of packaging,
sending, and receiving SOAP messages. You can create such a layer using a .NET assembly wrapper.
Figure 2. Leveraging .NET to Communicate with Web Services
A .NET assembly is a unit of deployment in .NET. Typically, it is a DLL or an executable built to run on the Common
Language Runtime (CLR) supported by the .NET framework. An assembly exports a class-based interface with properties and methods. Using .NET client support in LabVIEW, you can create an instance of a
class from an assembly using the Constructor Node, and you can access its properties and methods using the
Property and Invoke Nodes, respectively.
The following example shows how you typically use these nodes in a VI that uses .NET client support. Refer to
Chapter 19, Windows Connectivity, of the LabVIEW User Manual (linked below) for more information about using
.NET in LabVIEW.
Figure 3. Using .NET Objects in LabVIEW
See Also:
Product Manuals: LabVIEW User Manual Creating a .NET Assembly Wrapper
Using a .NET assembly wrapper greatly simplifies the process of communicating with a Web service. To create a
.NET assembly wrapper for a Web service, you need a tool that can take the WSDL specification of a Web service
and generate the .NET assembly wrapper. The .NET framework SDK provides a command-line utility called soapsuds.exe that generates a .NET assembly given the URL of a WSDL specification. However,
the tool has the following disadvantages:
The tool requires the .NET framework SDK to be installed.
It is a command-line tool.
The tool requires that you use a Web browser first to find the Web service and get the URL to its WSDL specification.
To address these issues, use the VI-based tool called the LabVIEW .NET Web Service Browser described in the next section. You can use this tool to
search for a Web service and generate the .NET assembly wrapper for it from within the LabVIEW development
environment.
.NET Web Service Browser
The LabVIEW .NET Web Service Browser combines a Web browser with .NET assembly generation to provide an
integrated solution. Before you start using the LabVIEW .NET Web Service Browser, you must do the following:
Install the .NET framework redistributable, which is available at the Microsoft Download Center (linked below). To
test whether a framework already exists, navigate to the windows\system32 directory and locate mscoree.dll. If
the file exists, you already have the .NET framework installed.
The LabVIEW .NET Web Service Browser uses Microsoft's Internet Explorer ActiveX control. If you do not have
Internet Explorer 6.0 or later, install it by downloading it from the Microsoft Download Center (linked below).
Download the LabVIEW .NET Web Service Browser (linked below).
After completing the above steps, launch LabVIEW. Select Tools?.NET Web Service Browser to display the tool, as
shown in the following example.
Figure 4. LabVIEW .NET Web Service Browser
The browser is a minimal version of a standard Web browser with only the back, forward, and go buttons and an
ddress bar. The browser starts in a preconfigured Web service directory such as XMethods. You can customize
the startup URL by clicking the down arrow of the address bar and selecting Edit Favorites from the shortcut menu.
You can use the Edit Favorites dialog box to configure your favorite Web service directories. After you browse the
Web service directory and get to the WSDL specification of a Web service, the Create Assembly button is enabled,
which you can click to create the .NET assembly wrapper for that Web service.
See Also:
Microsoft Download Center
LabVIEW .NET Web Service Browser
Creating a Web Service-Based Application
Using LabVIEW 7.0 or later and the LabVIEW .NET Web Service Browser, you can create a Web service-based application in the following three steps:
Browse and locate a Web service using the LabVIEW .NET Web Service Browser.
Create a .NET assembly wrapper for the Web service.
Employ the assembly in a VI using .NET client support.
The following example describes the steps necessary to build a VI to read the latest quote of a stock given its
ticker symbol.
Step 1. Browse for a Stock Quote Web Service
Launch LabVIEW.
Select Tools?.NET Web Service Browser.
Click the down arrow of the address bar and select www.salcentral.com, as shown in the following example.
Figure 5. Selecting a Web Service Directory
You can use SalCentral to search for a Web service using keywords. Enter "stock quote" in the search text box
and click the Search for Web Service button, as shown in the following example.
Figure 6. Searching for a Web Service
Because this is a popular search, the search results should contain several listings. Read the descriptions and
select a Web service that suits your needs. In this example, select StockQuoteNET. Step 2. Create a Stock Quote .NET Assembly Wrapper
After you select a Web service, you must find its WSDL specification. Typically, there is a link to the WSDL
specification, also known as a schema or WSDL address, in the Web service directory listing. In this example,
the Schema Location link points to the WSDL specification. After you click the link, the .NET Web Service Browser
displays a WSDL specification such as the following example.
Figure 7. WSDL Specification
When the .NET Web Service Browser is pointing to a valid WSDL specification of a Web service, the Create
Assembly button is enabled. Click the Create Assembly button to create the assembly wrapper.
When a file dialog box appears, save the assembly (DLL) in the directory of your top-level VI.
Step 3. Employ the .NET Assembly in a VI
In LabVIEW, create a new VI by selecting File?New VI.
Like in C++, objects in .NET are created using a constructor. Search for a Constructor Node on the Functions
palette and place it on the block diagram.
When the Select .NET Constructor dialog box appears, click the Browse button.
When a file dialog box appears, navigate to and select the assembly that you created in step 2.
The namespace WebServiceProxy should appear in the Objects list. Click WebServiceProxy to display the exported
class of objects, as shown in the following example.
Figure 8. Selecting a .NET Constructor
Select the StockQuote object and its default constructor from the Constructors list and click the OK button. The
Constructor Node is configured.
After you configure the Constructor Node, you can place Property and Invoke Nodes on the block diagram and use
properties and methods for the object created by the constructor. In this case, you want to obtain a quote for a
specified stock. Because you need to specify a ticker symbol input, the interface most likely will be a method.
Place an Invoke Node on the block diagram and wire up the reference output from the Constructor Node to the
input reference of the Invoke Node. Click the Invoke Node to display the available methods, and select the GetQuote
method. The block diagram should appear similar to the following example.
Figure 9. VI Retrieving StockQuote from a Web Service Using .NET
Save the VI in the same directory as the assembly. It is important that the assembly resides in the same directory
as the application because otherwise you receive a run-time error. In LabVIEW, the top-level VI is the application so make sure the assembly resides in the same directory as the top-level VI. In this case, you have only one VI and it is the top-level VI so you should save it in the directory of the assembly.
Run the VI. You should be able to retrieve delayed stock quotes for any ticker symbol you enter. Following these steps, you can build a Web service-based application in LabVIEW 7.0 or later. With the help of the LabVIEW .NET Web Service Browser, you can
locate Web services and generate assembly wrappers for them. After you create the assembly wrapper, you place
Constructor, Property, and Invoke Nodes on the block diagram and wire them up. It is simple to write complex
Web service-based applications using LabVIEW without having to learn SOAP, XML, or HTTP.
文章评论(0条评论)
登录后参与讨论