469,582 Members | 2,604 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,582 developers. It's quick & easy.

Implementing interface-based web services in .NET 2.0

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
End Enum

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

Public MustInherit Class WsDocumentsShim
Inherits System.Web.Services.WebService
Implements IWsDocuments

Public MustOverride Function ValidateConext(ByVal ThisCall As
CallContext) As String Implements IWsDocuments.ValidateConext
End Class
End Namespace
'Sample implementation web service:
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicPr ofile1_1)_
<Global.Microsoft.VisualBasic.CompilerServices.Des ignerGenerated()_
Public Class Service1 '(other services: Service2, Service3, etc.)
Inherits IWsDocuments.WsDocumentsShim

''' I use Shadows because compiler won't allow Overrides of web ref
Public Shadows Function ValidateConext(ByVal ThisCall As
IWsDocuments.CallContext) As String
If ThisCall.Version = "1.0" Then
Return "OK"
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))
Sep 13 '06 #1
1 1710
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:

for VS 2005: http://weblogs.asp.net/cweyer/archiv...11/212843.aspx
Sep 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Martyn Lawson | last post: by
4 posts views Thread by Frank J. Reashore | last post: by
5 posts views Thread by Colin McGuire | last post: by
3 posts views Thread by David Veeneman | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.