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