tags:

views:

87

answers:

2

Hello

i need to develop a .net library which exposes a java web service proxy to a legacy vb6 asp web application . Being the first time i do such a task and not knowing vb6 programming language, i need some clearifications by a more experienced programmers. To begin i've searched the web and i've found the following link (in case someone might find it useful ) : http://migrationguide.artinsoft.com/Migration-Guide-Faq-Chapter-14.aspx

yet there are still some things that aren't clear to me :

  1. the web service proxy's methods take complex types (objects) parameters and return complex types (for instance a list of "records" ) . How should i map thoose types to make them usable by vb6 : structures or classes (some of them are nested into other structures ) ? or arrays of simple types, eventually matrixes for nested types ?

  2. i think it's obviuos i can't use generics, but can i use collections or should i use only arrays ?

  3. what kind of exceptions should i throw from inside my library ? COMException ? Any kind of exception i whish ? and how does the vb6 web application consume them : i mean i'd like to give a better feedback than "and exception has been raised" . i've found some posts around but they are quite old and related to older version of the .net (actually i'm using 3.5 )

Thank you in advance for any help

A: 

We've done this recently by writing new WCF services that expose the service in a simple way that VB6 can handle. Like you say VB6 can't handle complex types as they are not generated by a proxy like .net would do for you. So our solution was to wrap (facade?) the existing service in something that VB6 could call.

Our service returned a string which contained an XML document that could be parsed in VB6 into the required object i.e. return an XML document containing 10 clients and then parse this into a collection of Client objects.

Once the WCF service was created you need to grab the WSDL and save it locally or point the code to the WSDL location, we had some trouble when trying to get the WSDL via HTTPS which is why we saved it locally.

To consume them we used the SOAP toolkit from MS.

Here's some example code for creating the request and parsing the result :-

Set m_ServiceClient = New MSSOAPLib30.SoapClient30

With m_ServiceClient
  .MSSoapInit "c:\service.wsdl"
  .ConnectorProperty("Timeout") = "30000"
End With

lLoading = ParseResultToLoading(m_ServiceClient.GetLoadingByCountryIdProductId(llProductId, _
                                                                             Countries(), _
                                                                             Duration, _
                                                                             lsTravellerType, _
                                                                             Traveller.MedicalScore, _
                                                                             Traveller.InitialAmount, _
                                                                             Traveller.AdditionalWeekAmount, _
                                                                             IssueDate))


Private Function ParseResultToLoading(XMLString As String) As Loading

  Dim x As Loading
  Dim objXML As New MSXML2.DOMDocument
  Dim objElem As MSXML2.IXMLDOMElement

  If Not objXML.LoadXML(XMLString) Then
      Err.Raise objXML.parseError.ErrorCode, , objXML.parseError.reason
  End If

  Set objElem = objXML.selectSingleNode("//LoadingInfo")

  Dim objSub As MSXML2.IXMLDOMElement

  ' iterate its sub-nodes
  For Each objSub In objElem.childNodes

      Select Case UCase$(objSub.tagName)
          Case "FIXED"
              x.Fixed = objSub.Text
          Case "FIXEDNET"
              x.FixedNet = objSub.Text
          'any other values that are required...
      End Select

  Next

  ParseResultToLoading = x

End Function

You can see in the code example that we passed arrays, strings, longs and dates into the service call without any problems. Can't use any .net return types (apart from the obvious ones!) as VB6 won't understand what they are. You can use a similar design to push information back to the service.

Regarding the exceptions to throw in your library we just used standard .net code to throw any exceptions we needed to or allowed existing exceptions to bubble up and you could get exception information via the MSSOAPLib30.SoapClient30 object it contains various fault properties.

All worked really well in the end, had no problems with it running and the best bit is that VB6 now uses exactly the same functionality as other .net clients.

Hope that gives you an idea of how we did it and that it may help you with your decisions. let me know if anything doesn't make sense or you want clarification on any of it.

Andy Robinson
hi Andy, thank you for the idea you've provided, by an architecrural point of view i fear i can't rewrite the web service, since it is a soa service exposed by a content management system not under my control. So at the end i've to write wrapping proxy classes vb6 can consume. Anyway thank you for your example , moreover i wasn't aware of the soap toolkit and it might get useful for other projects. just one doubt : i see it's deprecated
Stefano
No problem. We didn't rewrite the existing web service just added a new one in front of it :-) Soap toolkit does make it very easy to consume web services and yes is depreciated (isn't everything to do with VB6!) has been used in the project I work on for over 3 years without problems. There is also this other stackoverflow question that may contain information that you can use - http://stackoverflow.com/questions/122607/what-is-the-best-way-to-consume-a-web-service-from-vb6 - and then maybe not need the soap toolkit?
Andy Robinson
+1  A: 

In the end i've found that the raccomanded pratice is to expose the library as a Com object. In case other beginners like me might find it useful, the official msdn guide is :

msdn.microsoft.com/en-us/library/zsfww439(v=VS.71).aspx

Since arrays has caused me a bit of trouble the following hints might be helpful:

  1. arrays method parameter must be provided by ref not by value or you get an exception at runtime
  2. if there are properties returning or getting arrays you must specify how to marshal the values

below i've added the msdn guide to marshalling arrays and another post i've found useful:

msdn.microsoft.com/en-us/library/z6cfh6e6.aspx

huntjason.spaces.live.com/blog/cns!9D2E96F2AA6AE85F!378.entry

thank everybody for the opinions and examples provided

Stefano