ASPnews Home

News

Analysis

Trends

Strategies

ASP Directory

Community

About Us

Search ASPnews:



internet.com
Developer
Downloads
International
Internet Lists
Internet News
Internet Resources
IT
Linux/Open Source
Personal Technology
Small Business
Windows Technology
xSP Resources
Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
internet.commerce
Be a Commerce Partner
Cheap Plane Tickets
Digital Camera Review
Register Domain Name
Memory Flash Cards
Online Education
Batteries
T-Shirts
Remote Access
Advertising Trucks
Online Degrees
Best Digital Camera
Cheap Web Hosting
Digital Camera Review



ASPnews Focus
Top News:
» SOAs So Close, Yet So Far

» Why SaaS Is Making a Comeback

» Join the Discussion: ASPnews.com's industry forums

Plus:
» More ASP News

TOP 50
Top 20 Providers
 & Top 30 Enablers
Free Newsletter!



ASPnews Shortcuts
Week's Top News

ASP News at internetnews.com

Industry Events

Discussion Forums

Industry Basics

Site Guide

By partnering with HP, Dynamic Net kept customer turnover low and obtained new business. Learn how HP servers solidify Dynamic Net’s IT infrastructure and helped them increase margins.

STRATEGIES
 


Dev: Building Distributed Apps? Use XML Web Services, Not .NET Remoting (Mostly)
By Paul Kimmel

December 16, 2004

Continued from Page 3

Invoking an Imported Web Method

After importing a Web service, invoking its Web methods is the same whether the Web method accepts or returns values and whether or not these values are simple or composite types. Number and complexity do not matter at this point. From the consumer’s perspective, it is just a matter of creating objects and calling methods.

Note: If you are writing software for an internal customer and performance is an issue, you might want to bypass Web services altogether. Because optimization is a task best performed near the end of development, Web services are better suited to external or distributed consumers as opposed to internal, local consumers.

As is true with any namespace and class, you need to have access to the assembly and its namespaces before you can use what it offers. The namespace for a Web service is generally some variation on the host name. For example, if you have IIS installed on your workstation, create a Web service on your workstation and import that Web service. WSDL/SPROXY will generate a namespace such as localhost or localhost(n). These variations in name are used because WSDL/SPROXY creates a unique folder in your project for the Web service, and this folder contains .map, .vb, .disco, and .wsdl files.

Files with a .map extension indicate the name and location of all of the related files. The .vb file is actually the generated source code. (Click the Show All Files toolbar button in the Server Explorer to see the .vb source code file.) The .vb source file contains wrappers for synchronous and asynchronous calls to the Web service and generated definitions for composite types if they are relevant to the Web service. You can explore the .vb file and even modify it if you like, but generally that is not wise. Listing 2 shows the generated source code for the referenced HelloWorld Web method.

Listing 2: All of this complicated-looking code is generated by SPROXY, which is invoked by the WSDL utility.

'------------------------------------------------------------------
' <autogenerated>
'     This code was generated by a tool.
'     Runtime Version: 1.1.4322.573
'
'     Changes to this file may cause incorrect behavior and will
'     be lost if the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------
Option Strict Off
Option Explicit On
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
'
'This source code was auto-generated by Microsoft.VSDesigner,
'Version 1.1.4322.573.
'
Namespace localhost2
    '<remarks/>
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.ComponentModel.DesignerCategoryAttribute("code"),  _
     System.Web.Services.WebServiceBindingAttribute(  _
          Name:="Service1Soap", [Namespace]:=  _
          "http://tempuri.org/WebService1/Service1")> _
    Public Class Service1
        Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
        '<remarks/>
        Public Sub New()
            MyBase.New
            Me.Url = "http://localhost/WebService1/Service1.asmx"
        End Sub
        '<remarks/>
        <System.Web.Services.Protocols.SoapDocumentMethodAttribute(
             "http://tempuri.org/WebService1/Service1/HelloWorld",
             RequestNamespace:="http://tempuri.org/WebService1/Service1",
             ResponseNamespace:="http://tempuri.org/WebService1/Service1",
             Use:=System.Web.Services.Description.SoapBindingUse.Literal,
             ParameterStyle:=  _
                  System.Web.Services.Protocols.  _
                  SoapParameterStyle.Wrapped)>  _
        Public Function HelloWorld() As String
            Dim results() As Object = Me.Invoke("HelloWorld", _
                                                New Object(-1) {})
            Return CType(results(0),String)
        End Function
        '<remarks/>
        Public Function BeginHelloWorld(ByVal callback _
               As System.AsyncCallback, ByVal asyncState _
               As Object) As System.IAsyncResult
            Return Me.BeginInvoke("HelloWorld", New Object(-1) {}, _
                                  callback, asyncState)
        End Function
        '<remarks/>
        Public Function EndHelloWorld(ByVal asyncResult _
               As System.IAsyncResult) As String
            Dim results() As Object = Me.EndInvoke(asyncResult)
            Return CType(results(0),String)
        End Function
    End Class
End Namespace

The XML Web services technology in .NET manages all of this code for you. All you have to do is treat the Web service like a black box and interact with its external interface. Listing 3 shows how easy it is to call the HelloWorld Web method.

Listing 3: Call a Web service’s methods like any other method, by creating an instance of the class and invoking the method.

Module Module1
    Sub Main()
        Dim Service As localhost2.Service1 = New localhost2.Service1
        Console.WriteLine(Service.HelloWorld())
        Console.WriteLine("press enter")
        Console.ReadLine()
    End Sub
End Module

In the code, you declare an instance of the Web service, including the namespace. By default, the Web service is named Service1. Like any other object, I need to create an instance of the class and then simply invoke the class’s behaviors.

Page 5: Advanced Web Service Information

Go to page: Prev  1  2  3  4  5  Next  

Email this Article
View Printable Version
Back to Strategies

 

Featured Links
Learn the secrets of the popular search engines!
Free Web Hosting Buyer's Guide -- Click Here!
Enhance your Web site with the Dynamic HTML HierMenus Code


JupiterWeb networks:

internet.comearthweb.comDevx.comGraphics.com

Search JupiterWeb:

Jupitermedia Corporation has three divisions:
Jupiterimages, JupiterWeb and JupiterResearch

Copyright 2005 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | Shopping | E-mail Offers


Give us your Feedback