Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / September 2006

Tip: Looking for answers? Try searching our database.

Implementing interface-based web services in .NET 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
oldVB3r - 13 Sep 2006 22:04 GMT
I would like to create a set of web services that share a common set of types
(classes, structures, enums). I know I can create a VS 2005 web service based
on the Interface statement to contain these common types. The problem is that
I cannot determine how to create the implementation web services in a way
that I can cast the common types between proxy object parameters in a client
app. Please check the snippets of my code:

'Interface web service:
Namespace MyServices

   Public Class CallContext
       Public Environment As String
       Public Version As String
   End Class

   Public Enum Environments
       Dev
       UAT
       Prod
   End Enum

   <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1,
Name:="IWsDocuments", Namespace:="http://interfaces.MyCorp.com/")> _
   Public Interface IWsDocuments
       <WebMethod(), _
       SoapDocumentMethod(Binding:="IWsDocuments")> _
       Function ValidateConext(ByVal ThisCall As CallContext) As String
   End Interface

   <WebService(Namespace:="http://interfaces.MyCorp.com/")> _
   Public MustInherit Class WsDocumentsShim
       Inherits System.Web.Services.WebService
       Implements IWsDocuments

       <WebMethod()> _
       Public MustOverride Function ValidateConext(ByVal ThisCall As
CallContext) As String Implements IWsDocuments.ValidateConext
   End Class
End Namespace

'Sample implementation web service:
<WebService(Namespace:="http://interfaces.MyCorp.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service1 '(other services: Service2, Service3, etc.)
   Inherits IWsDocuments.WsDocumentsShim

   ''' I use Shadows because compiler won't allow Overrides of web ref
object??
   <WebMethod()> _
   Public Shadows Function ValidateConext(ByVal ThisCall As
IWsDocuments.CallContext) As String
       If ThisCall.Version = "1.0" Then
           Return "OK"
       Else
           Return "This version not supported"
       End If
   End Function

   'Add implementation specific methods here:
End Class

'Client app:
       Dim cnc As New Service1Proxy.Service1
       Dim context As New Service1Proxy.CallContext
       With context
           .Environment = Service1Proxy.Environments.Dev
           .Version = "1.0"
       End With
       txtResults.Text = cnc.ValidateConext(context)

       Dim cnc2 As New Service2Proxy.Service2
       '''' Invalid Cast Exception occurs below:
       txtResults.Text &= vbCrLf & vbCrLf &
cnc2.ValidateConext(DirectCast(context, CncService2Proxy.CallContext))
oldVB3r - 14 Sep 2006 15:39 GMT
Did some more research and came up with the answer. You have to fiddle with
the proxy generation for the client, there's no automatic way of doing this
in Visual Studio. Here are two article to look at:

for VS 2003:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/
service07162002.asp


for VS 2005: http://weblogs.asp.net/cweyer/archive/2004/08/11/212843.aspx

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.