Results 1 to 17 of 17

Thread: Please could someone help me with a code example in .NET

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Please could someone help me with a code example in .NET

    I am currently using VB6 and to be quite fair I am getting really sick of people saying "well, use .NET" when I ask a question about VB6.

    The following is my current app design:

    ALL these sit on one PC.

    SQL Server DB
    DataObjects.Dll
    SvrProxy.Dll
    CliProxy.Dll
    ClientObjects.Dll
    Client.EXE

    So, a pretty straight forward n-teir app design, nothing special.

    Currently I have only one table, Users.
    In my clientobject.dll I have 2 classes User, and Users. Users is a collection class.

    I click Load in my client.exe and this retrieves the data from the DB and displays it in a grid.

    How would this be done in .NET?
    Would I keep the same DLL's?
    Would I keep the same classes in these objects?

    I don't suppose someone has an exmple of an app like mine above, or could someone write me one?

    How would I pass the data to the UI?

    Woka

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Most of these questions don't have straight forward answers. I mean what objects are in those dlls and what do those dlls do? If there is just a user class and collection that seems like a bit many dlls for that. Also do you mean that these are all on a 'server' type computer and not where the 'client' exe is? Another question would be if so then what is the reasoning? Deployment?

    Deployment is much easier in .NET since you don't have to register any dlls. Also you could probably get away with using the same dlls BUT to take full advantage of .NET you would probably want to rewrite them.

    How are you passing the data to the UI now?

    If you want to upload the VB6 version maybe one of us will translate it to .NET (providing it isn't too big a beast).

  3. #3

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    DataObjects.DLL has a class called cUserSvr:
    [Highlight=VB]
    Public Function LoadUsers() As String 'Return is XML
    'Code to connect to DB and return
    'the data in XML format
    'My XML contains header info (columns), datatype, col name etc
    'and the XML also contains all user data
    End Function

    SvrProxy.DLL has a class called cProxy:
    VB Code:
    1. Public Function ExecuteCommand(Byval pstrCommand as string) As String
    2.    Select Case pstrCommand
    3.       Case "LoadUsers"
    4.           Dim objSvr As cUserSvr
    5.           Set objSvr = New cUserSvr
    6.           ExecuteCommand = objSvr.LoadUsers
    7.          Set objSvr = Nothing
    8.       case Else
    9.           Err.Raise vbObjectError,, "Command not recognised"
    10.    End Select
    11. End Function

    Make sense so far?

    CliProxy.DLL has a class called cGateway:
    VB Code:
    1. Public Function ExecuteCommand(Byval pstrCommand as string) As String
    2. Dim objProxy As SvrProxy.cProxy
    3.    Set objProxy = New SvrProxy.cProxy
    4.    ExecuteCommand = objProxy.ExecuteCommand(pstrCommand)
    5.    Set objProxy = Nothing
    6. End Function

    In ClientObjects.DLL I have a few classes that represent the XML that is broughtback.
    I have created my own datasource, which is similar to a Dataset in .NET, but with ALL of the fucntionality But it does the trick.
    I then pass these classes into a usercontrol, in the Client.exe, I made and that then sets up the grids columns and rows.

    Thje reason its written like this is because I can place any communication method in between the proxy DLLs and my app will still work...at the moment I use winsock here, but ti can easily be changed to all run on the same PC and the proxy DLLs will talk to each other directly.

    Does all that make sense?

    Woka

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well this would typically be accomplished with Web Services or Remoting. Also Datasets natively support XML I/O. There also wouldn't really need to be a usercontrol or a datasource specifically since .NET can use databinding with any object.

    I'm not sure what you mean by a 'Dataset but with ALL of the funcationality'.

    If for some reason there was still a need to encapsulate the calls to get the data (in this case from a web service) you could do that too.

  5. #5

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Right. You have lost me already...sort of.
    Web Service? Is this the only way?

    I hope not as I wouldn't have a clue where to start.

    I need to write a client server app. Simple. I use winsock in VB6. Web Services in .NET?
    The problem with that is I know nothing.

    The examples I have found, if they can be called examples, are just a waste of time, and it seems everyone I talk to knows how to do it, but can't give me working code, or enough details on how to achieve this.

    So far I have seen that .NET isn't all that it's cracked up to be. In fact, it's pissing me off the fact that SOOO many people sing it's praises, and yet no one can show me why. They just quote computer technical jargon at me, at which point I switch off

    Have you got any code to do this, or point me in the direction of a decent exmaple on the web?

    Woka

  6. #6

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Plus, I don't like binding...never have, never will
    Do you have to bind it? Is .NET binding better than VB 6?
    I don't like the fact that I have no control over how the data is displayed.

    Also...VB6 OCX's won't work in .NET will they?

    Woka

  7. #7
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    My guess as to the lack of replies here speaks to, perhaps, a certain vagueness in your question(s).

    Can I create a client-server app? Of course, but you already knew that.

    But more specifically, can I write something that connects to a data source, passes serialized XML data back to a client where the data can then by displayed though a control(s)? And of course, the answer is again, yes.

    Unfortunately this all seems like stuff you already know. I guess my question is where did your examples fall short? What were you looking for?

    As far as databinding, it's a bit of a shame VB6 ruined it for everybody b/c it's lots better in .Net - far less black box. But many were burned and won't go back - myself included. So no, you don't have to databind.

  8. #8
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    It took me a while, but I actually like the dotnet Datagrid for data binding. I think it takes alot of customizing to make it look decent, but I think once you learn the customizations, it works very well.

    As far as VB.NET over VB6, I'd sing it's praises just for becoming a true object oriented language. I would say it is the only decent version of VB out there.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here you go. Here is an example using a webservice. I am running the web service from my server for now and I'll leave it up for a day or two so if you want to test using a remote server its all good. The Woka folder in the zip is the web service and the WokaClient folder is well the client app. I stuck some comments in a few places to add some guidence.

  10. #10

  11. #11

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Ok here it is in ZIP format.
    Attached Files Attached Files

  13. #13

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    No problem. Some other interesting facts about Web Services: There are some security Enhancements out there that you can download, also since they are hosted from IIS you can require user credentials to be passed in if you want. You can do this via the NetworkCredentials object of the Service object (I think thats the name). You can only pass things that are Serializable over the web. Classes that a Web Service exposes get converted to almost like a Structure (Type in VB6) where only Public members are visible and they are no longer encapsulated in properties.

    There is also Remoting which can do this sort of thing and that can be much more powerful but is equally more a pain in the ass (sometimes).

  15. #15

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    OK, you have lost me now
    One step at a time.

    I am currently looking at adding security in the form of session IDs. I have a book, ASP.NET - Unleased by Stephen Walther. It suggests using:
    VB Code:
    1. Public Class ServiceTicket
    2.     Public IsAuthenticated As Boolean
    3.     Public SessionKey As String
    4.     Public Expiration As DateTime
    5. End Class
    Does this look familier?
    I have been told you can pass the sessionID as a header instead of a varible, but this just confused me Will work it out in the end.
    Do all client server apps in .NET use IIS web services?
    When would you use Sockets instead of IIS?

    Woka

  16. #16
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    You can still use sockets, but I would suggest .Net Remoting. In it's simplest form, what remoting let's you do basically is create a reference to an object from one application to another. So basically you can setup a host application that exposes an object that contains the functionality you want to be able to control remotely, and then on a client application, you create a reference to that object, and then it basically works as if it were a local object, except it is actually running on a remote AppDomain in another process.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  17. #17
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The trouble is with pure sockets you have to write your own protocol to communicate through them. WebServices and Remoting are just using sockets behind the scenes and provide a protocol for you to use. Yes that is what a WebService class will look like. You can use IIS for your authentication if you want as mentioned (but the name is just Credentials). Just turn off anonymous access in IIS and set whatever credentials you want to allow access then in code you can apply credentials like this:
    VB Code:
    1. Dim ws As New com.edneeis.[url]www.WokaService[/url]
    2.         'here it sets the login info
    3.         ws.Credentials = New Net.NetworkCredential("myUsername", "myPassword", "domainTooIfNeeded")
    4.         Dim ds As DataSet = ws.GetDataSet

    Or you can use Remoting, as SeanGrebey mentioned, but if you are new to .NET then you may want to wait a little while for Remoting as in my opinion WebServices are easier to use but not as powerful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width