Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2006, 11:51 AM
Registered User
 
Join Date: Dec 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access properties & methods from a WebService

I’m fairly new to .NET. I’ve been developing in .NET for about 6 months. I have over 10 years experience with VB in general.

Here’s what I have done so far:

1. Project is entirely .NET
2. Working with VS.net 2003, Framework 1.1, and WSE 2.0
3. Created 1 Webservice
4. Added 9 projects to it. All developed in VB.net (6) and C# (3)
5. Added all the necessary references to the .asmx to access these projects

Here is the issue I have:

1. How do I expose the properties and methods residing in my external projects I added to my Webservice Solution, so my Web App can access them?
2. Each of these external projects have many classes in them with the properties and methods I need.
3. I added a reference to my Web App to my Service.

I have tried adding Imports statements to the .asmx but I still have no access to the properties and methods.

I tried creating a Public Class and adding an Inherits statement to my external project, so my Web App can gain access to these classes though my Web Service. However I am unable to just add a Parent Inherits statement without drilling down to the lowest child level. If I don’t, it asks for a Type Expected. Is there a better way to do this?

Just an FYI, all 9 of these projects are in my Web App currently and I want to pull them out and access them though my Web Service instead. Any help you can provide would be greatly appreciated.

Thanks,
 
Old January 17th, 2006, 11:57 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

First, I'd like to clarify something (the terms you used don't seem entirely correct. From what I'm reading, this is what you have:

- Visual studio solution with 10 projects
- 1 of the projects is a web service project (truly a web application project)
- Web service project references the other 9 projects

1 question regarding "I added a reference to my Web App to my Service.": What web app are you referring to? Is the "service" you refer to the web service project?


Web services function my exposing methods written in the web service class (the *.asmx.vb file(s)) as "WebMethod"s. If you have standalone methods in your supporting projects that you can call independently then you could create matching method signatures on your web service class and then call the support class methods from them, returning the result on the web method.

If you have more extensize processes that need to go on, then you might want to look into a remoting solution.

-Peter
 
Old January 17th, 2006, 02:30 PM
Registered User
 
Join Date: Dec 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the confusion. Yes, the Service I am referring to is my Web Service Project (i.e. Service1.dll). To clarify things I have a:

1. Web Service Solution with 9 other projects associated with it.
2. Web Application Solution

My Web App Solution contains a reference to my Web Service. Since my Web Service and these various projects have different Root Namespaces I have to fully qualify them using the Imports Statement in my .asmx.

When I do this, shouldn’t I have access to those classes in these projects with their properties and methods from my Web App, so long as I have a reference in my Web App pointing to this Web Service? I would think so, but I don’t.

Here’s what my code looks like in my Service:

Imports Project1
Imports Project1.Data
Imports Project1.Model
Imports Project1.DataAccess
Imports Project1.Security
Imports Project1.SystemConfig

Imports System
Imports System.Xml
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' WSE Namespaces

Imports Microsoft.Web.Services2
Imports Microsoft.Web.Services2.Addressing
Imports Microsoft.Web.Services2.Messaging
Imports Microsoft.Web.Services2.Security
Imports Microsoft.Web.Services2.Security.Tokens
Imports Microsoft.Web.Services2.Security.X509
Imports Microsoft.Web.Services2.Security.Policy

<System.Web.Services.WebService(Namespace:="http ://tempuri.org/ApolloService/ApolloService")> _

Public Class ApolloService

    Inherits System.Web.Services.WebService

End Class

It’s very basic right now until I start adding Security. Currently the first 6 Imports are References in my Web App but I want to pull them out, and have them referenced in my Web Service instead, then just have a single reference in my Web App to this Service.

Quote:
quote:Originally posted by planoie
 First, I'd like to clarify something (the terms you used don't seem entirely correct. From what I'm reading, this is what you have:

- Visual studio solution with 10 projects
- 1 of the projects is a web service project (truly a web application project)
- Web service project references the other 9 projects

1 question regarding "I added a reference to my Web App to my Service.": What web app are you referring to? Is the "service" you refer to the web service project?


Web services function my exposing methods written in the web service class (the *.asmx.vb file(s)) as "WebMethod"s. If you have standalone methods in your supporting projects that you can call independently then you could create matching method signatures on your web service class and then call the support class methods from them, returning the result on the web method.

If you have more extensize processes that need to go on, then you might want to look into a remoting solution.

-Peter
 
Old January 17th, 2006, 04:15 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The Imports statement does nothing more than allow you to "abbreviate" class names. For example, if you use "Imports System.Data.SqlClient" you can access the "SqlCommand" type without having to fully qualify it ("System.Data.SqlClient.SqlCommand").

Project references are unrelated to the Imports keyword. In order to use classes in another assembly, you must reference that assembly. You can do all of that without a single "Imports" statement.

When you create a web reference to a web service, Visual Studio will generate a service proxy class that creates a class named with the name you gave for the reference. It will then create methods on that class that match all the exposed web methods of the service as defined in the services WSDL. Other assemblies referenced by that service can be USED by the code for that service, but are not implicitly exposed by the service. You have to explicitly create web methods that exposed the functionality you wish to make public.

-Peter
 
Old January 17th, 2006, 04:48 PM
Registered User
 
Join Date: Dec 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In other words, if I what to access say Project1.Data.GetARecord Method from my Web App, I would need to create a Public Class in my MyService.asmx like this:

<System.Web.Services.WebService(Namespace:="http ://tempuri.org/MyService")> _
Public Class GetARecord
    Inherits Project1.Data.GetARecord
End Class

and remove my Imports since I have the Reference to Project1.Data in my MyService.asmx already.


Quote:
quote:Originally posted by planoie
 The Imports statement does nothing more than allow you to "abbreviate" class names. For example, if you use "Imports System.Data.SqlClient" you can access the "SqlCommand" type without having to fully qualify it ("System.Data.SqlClient.SqlCommand").

Project references are unrelated to the Imports keyword. In order to use classes in another assembly, you must reference that assembly. You can do all of that without a single "Imports" statement.

When you create a web reference to a web service, Visual Studio will generate a service proxy class that creates a class named with the name you gave for the reference. It will then create methods on that class that match all the exposed web methods of the service as defined in the services WSDL. Other assemblies referenced by that service can be USED by the code for that service, but are not implicitly exposed by the service. You have to explicitly create web methods that exposed the functionality you wish to make public.

-Peter
 
Old January 23rd, 2006, 12:32 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to create a web service class (ASMX) that exposes all the methods you wish to utilize. For example, if you want to expose the methods of Project1.Data thru web services, then you could do something like this:

<System.Web.Services.WebService(Namespace:="http ://tempuri.org/MyService")> _
Public Class Project1Data
    Inherits System.Web.Services.WebService
    '*** You must inherit from the class that makes this a web service. ***

    '*** Here, expose each underlying class method as a web method ***
    '*** The method signature should match the underlying method ***
    <WebMethod()> Public Function GetARecord(criteria As String) As DataSet
          Return Project1.Data.GetARecord(criteria)
    End Function

    '****************************
    'Create as many functions as you need to provide
    'access to the underlying methods of the other classes.
    '****************************

End Class

-Peter
 
Old January 23rd, 2006, 01:29 PM
Registered User
 
Join Date: Dec 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is what I thought you were saying, and what I have seen elsewhere on the Internet.

If I have to recreate my functions as <WebMethod()> in my ASMX, then what is the purpose of a WebService? I must be under the wrong impression of what the uses of a WerService is. I was under the impression that WebServices gave you the ability for other Apps to reuse code rather than recreate it each time.

Quote:
quote:Originally posted by planoie
 You need to create a web service class (ASMX) that exposes all the methods you wish to utilize. For example, if you want to expose the methods of Project1.Data thru web services, then you could do something like this:

<System.Web.Services.WebService(Namespace:="http ://tempuri.org/MyService")> _
Public Class Project1Data
    Inherits System.Web.Services.WebService
    '*** You must inherit from the class that makes this a web service. ***

    '*** Here, expose each underlying class method as a web method ***
    '*** The method signature should match the underlying method ***
    <WebMethod()> Public Function GetARecord(criteria As String) As DataSet
         Return Project1.Data.GetARecord(criteria)
    End Function

    '****************************
    'Create as many functions as you need to provide
    'access to the underlying methods of the other classes.
    '****************************

End Class

-Peter
 
Old January 23rd, 2006, 04:06 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The purpose of the web service is to provide a HTTP interface to executing your methods. The WebService class from which you derive your ASMX classes handle all the underlying details of constructing this HTTP interface. It creates the WSDL so that consumers of the service can discover what you expect from them and what they expect from you. It handles all the de/serialization of the incoming and outgoing data so that you don't have to write all of that.

How is this recreating code? Sure, you need to duplicate the method signature but that isn't asking much. Think of it like this: when you create an internal variable in a class and want to expose it to the public for the class' consumer to see, you create a public property on the class. It expect the type to match the internal variable. A web method is like a more complicated version of that. You are providing public access via the web service to a private method inside your classes.

-Peter
 
Old January 24th, 2006, 02:02 PM
Registered User
 
Join Date: Dec 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peter.



Quote:
quote:Originally posted by planoie
 The purpose of the web service is to provide a HTTP interface to executing your methods. The WebService class from which you derive your ASMX classes handle all the underlying details of constructing this HTTP interface. It creates the WSDL so that consumers of the service can discover what you expect from them and what they expect from you. It handles all the de/serialization of the incoming and outgoing data so that you don't have to write all of that.

How is this recreating code? Sure, you need to duplicate the method signature but that isn't asking much. Think of it like this: when you create an internal variable in a class and want to expose it to the public for the class' consumer to see, you create a public property on the class. It expect the type to match the internal variable. A web method is like a more complicated version of that. You are providing public access via the web service to a private method inside your classes.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
control properties and methods access problem erictamlam C# 2005 8 April 16th, 2007 02:23 PM
Defining Methods for a WebService ename .NET Web Services 0 November 21st, 2006 12:01 PM
methods and properties reference rmoguel Crystal Reports 0 January 31st, 2006 07:38 PM
Properties/Methods Not in Object Browser ritag VS.NET 2002/2003 0 January 13th, 2005 12:59 PM
Properties of WebService sakalou J2EE 0 February 3rd, 2004 02:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.