1. Log in now to remove adverts - no adverts at all to registered members!

Good or Bad?

Discussion in 'General Chat' started by DevAdvocate, Nov 4, 2014.

  1. stopmeandslapme

    stopmeandslapme Well-Known Member

    Joined:
    Mar 24, 2011
    Messages:
    20,378
    Likes Received:
    10,340
    Thanks. Trouble is I've no idea what you are talking about as this is all stuff I've never used.
    Basically by end of play tomorrow I've got to produce a web service which returns data from a sql server db in json format so our javascript can call it and populate our vash files. Or I might have to stick a dll or two in there. Could do with some example code. When I talk or read about this **** it all sounds like gobbledegook but when you get stuck in it starts to make sense.
     
    #21
  2. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    SQL Server can return queries as XML as opposed to normal result sets. XML is very easy to convert to JSON via XSL.

    Dunno what vash files are. :huh:

    You don't know what DLL's are. If you did you wouldn't be talking about them like that.

    If you want example code am happy to help :grin:
     
    #22
  3. Vilsmeier-Haack Reaction

    Vilsmeier-Haack Reaction Well-Known Member

    Joined:
    Jan 27, 2011
    Messages:
    11,691
    Likes Received:
    1,014
    Quit talking ****e
     
    #23
  4. Mick

    Mick Probably won't answer PMs Staff Member

    Joined:
    Jan 20, 2010
    Messages:
    11,325
    Likes Received:
    926
    What language are you working with?

    I use JSON.net with my c# **** - could knock you up something in about 5 mins in the morning if you're still struggling.
     
    #24
  5. stopmeandslapme

    stopmeandslapme Well-Known Member

    Joined:
    Mar 24, 2011
    Messages:
    20,378
    Likes Received:
    10,340
    I think I'll be ok getting the web service to fetch data from the db in json format, just calling it from our stuff is where i'll struggle. Maybe need a dll in between the javascript and the web service? Vash files are I think from Angular, either that or Node. All new stuff to me.
     
    #25
  6. Mick

    Mick Probably won't answer PMs Staff Member

    Joined:
    Jan 20, 2010
    Messages:
    11,325
    Likes Received:
    926
    No, you shouldn't need a DLL (unless you plan to share the code across various projects). Your web service can connect straight to the database, it's the middle layer, then the JavaScript contacts to the webservice directly.
     
    #26

  7. stopmeandslapme

    stopmeandslapme Well-Known Member

    Joined:
    Mar 24, 2011
    Messages:
    20,378
    Likes Received:
    10,340
    OK...my understanding is:
    Vash files (Angular.js or Node.js?) which have javascript files which do **** to the json data which (at the moment) is coming from a dll which calls direct to the db.
    I've got to replace the dll communicating with the db with a web service in web api 2 which is some asp.net thing for which i had to install visual studio 2013.
     
    #27
  8. stopmeandslapme

    stopmeandslapme Well-Known Member

    Joined:
    Mar 24, 2011
    Messages:
    20,378
    Likes Received:
    10,340
    I thought that's probably how it should work but the boss mentioned a dll so i dunno what he's thinking.
     
    #28
  9. Mick O'Toon

    Mick O'Toon Well-Known Member

    Joined:
    Jan 27, 2011
    Messages:
    34,059
    Likes Received:
    27,730
    I think he mean't dill with your fish
     
    #29
  10. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    ...and there is the ****e I was talking about avoiding.
     
    #30
  11. Mick

    Mick Probably won't answer PMs Staff Member

    Joined:
    Jan 20, 2010
    Messages:
    11,325
    Likes Received:
    926
    Here's a simple example using .NET http://www.codeproject.com/Articles/167159/How-to-create-a-JSON-WCF-RESTful-Service-in-sec

    Note this bit (which doesn't come out too well on here)

    It's the 'GetData()' method that you will be looking to connect to the database in and return whatever values it is look for (as defined in the class 'Person'). I'd recommend using LinqToSQL as a quick way to retrieve whatever data you need from the database.

    In terms of the Javascript interaction with the JSON rest service - you'd basically be looking for your .net service to mimic the expected json structure that is currently being read, then just point the javascript to the new service?
     
    #31
  12. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    No.

    DLL's live on the operating system (they are a Dynamic Link Library (DLL)). If written in a .NET language such as C# they can also be easily embedded into SQL Server. If native DLL's they can be connected to and called from SQL Server but that's a ridiculously stupid and complicated thing to do.

    You don't have DLL's in between anything. They're shared code called by your code.

    Ok, back to basics.

    What do you have at the moment?

    You seem to think you have a callable web service. Is so, in a web page call it's URL from Javascript using an XHR instance. That will return the JSON to you which you can then use JavaScript to manipulate the JSON.

    Alternatively, use the AJAX.NET bollocks in which case yer on yer own and am out.
     
    #32
  13. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    ...and more AJAX.NET ****e.

    You don't need it. Keep it simple by using JavaScript and XHR. You get the added bonus of keeping your front end separate from the back end (IIS or Apache) by simply replacing the service URLs.

    For example

    http://mysite/services/getdata.ashx

    when on IIS, and

    http://mysite/services/getdata.php

    when on Apache.

    Either way the getdata service returns the expected JSON to the front end for consumption by the calling page's JavaScript.
     
    #33
  14. Mick

    Mick Probably won't answer PMs Staff Member

    Joined:
    Jan 20, 2010
    Messages:
    11,325
    Likes Received:
    926
    I've just read the start of this thread and realised that they have specifically asked for Web API 2 (as a test, rather than a practical task), which is not the example I gave.

    Anyway I haven't worked with this yet (and I've just put it on the list of things to learn whilst still being paid in my current job, before my current job goes, so I can whore off the skills to the next employer) - but this seems to be a decent example using Jquery http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

    **** knows how to make it output JSON

    ---

    edit I've just actually read through this article and it outputs JSON - so this should be sufficient by itself.
     
    #34
  15. Mick

    Mick Probably won't answer PMs Staff Member

    Joined:
    Jan 20, 2010
    Messages:
    11,325
    Likes Received:
    926
    It's JSON.NET, nobody has used AJAX.NET in about 10 years <whistle>
     
    #35
  16. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    Erm, it is still AJAX. Just because Microsoft choose to call it a different name means **** all. It's still the XHR object being used to GET/POST asynchronous requests.

    If you want to rely on Microsoft generated ****e to wrap the basics up and bind you to their platform that's up to you.
     
    #36
  17. Mick

    Mick Probably won't answer PMs Staff Member

    Joined:
    Jan 20, 2010
    Messages:
    11,325
    Likes Received:
    926
    I tried to edit it to AJAX.NET quickly before you got yer reply in, which was back in the .net 2.0 days. Anyway - they have asked him to do it in Visual Studio so he should probably follow the Microsoft getting started guide - he can make his mind up on how clean he wants his future code to be if he still has a job next week.
     
    #37
  18. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    ...furthermore, never heard of JSON.NET

    Why the **** would you need a library to generate/consume JSON? JavaScript already understands JSON, it is it's own object notation after all.

    So that leaves us with generating JSON for returning over a web service. Yep, all kinds of bollocks Mircrosoft makes available for that. Writing C# objects with particular attributes for example and being forced to use a particular web service type that forces you write said C# objects.

    I've actually seen morons do that. They pull data from a database, transform the data result set into C# objects just so they can have "automatic" conversion into JSON <laugh>

    Any time the schema changes they have to rewrite their C# objects to keep up with this really neat automatic way <laugh>

    ****in morons
     
    #38
  19. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    I've nothing against using Microsoft technologies. In fact, that's mostly what I use. It's important to realise that most of it is ****e, particularly when it comes to web technologies.

    Use the good bits and eschew the ****e bits.
     
    #39
  20. Gambol

    Gambol George Clooney's wee brother

    Joined:
    Jan 22, 2010
    Messages:
    60,585
    Likes Received:
    18,242
    I've nothing against using Microsoft technologies. In fact, that's mostly what I use. It's important to realise that most of it is ****e, particularly when it comes to web technologies.

    Use the good bits and eschew the ****e bits.
     
    #40

Share This Page