locked
Metro Webservice Understanding RRS feed

  • Question

  • Basically I'm a new win8 and c#. My coding background includes mainly c programming and some java programming for Android. I've built a few basic apps now in XAML/c# and now want to take it to the next level. My previous database experience is using php to connect a website with apache but this seems like a whole different thing compared. Could someone clarify/acknowledge my thought process on webservices.

    I need to create a WFC service (aka web service) inside my metro app to communicate with a database. Basically i create a general method for each REST service (get, put, post, delete) I then add created WFC to my metro app through the 'add service' under references and point the address to the stored WFC (through reading I've seen people pointing to real website for a weather service).

    In php I would connect it with the DB with this

    <?PHP $user_name = "root"; $password = "password"; $database = "orders"; $server = "127.0.0.1"; mysql_connect($server, $user_name, $password); print "Connection to the Server opened";

    ?>

    So this information would have to be included inside the WFC service. How exactly as i've only found WFC examples using websites??

    Basically the only thing the my Metro app will do is  to send the WFC information on table to select, variable to send, data to recieve?

    I'm making a LOB app where you enter the Work Order number and all information of that work order will appear. (parts needed, QTY needed etc) so I wont be sending more than a number but i'll be recieving alot.

    I've also read that you can localhost for troubleshooting inside VS but when launched my webserivce has to be on a different computer then the metro app to connect to? OR is that only based on apps that will go to windows store. (isn't really a problem )

    Any help would be great.

    Thursday, September 6, 2012 2:26 PM

Answers

All replies

  • WCF is something of .net; ofcourse you can make a webservice in PHP too. i think its easiest that you use rest and then just return xml or json. In metro style apps you can talk to your php webservices with the HttpClient and get the result. You have to parse the results of the webservice your self. Depending what you return you can use the DataContractSerializer or the JsonDataContractSerializer.

    To see what you need simple create a object and serialize that to json or xml. then you know what your webservice has to deliver.

    Thursday, September 6, 2012 3:44 PM
  • Alright so let me see if this is correct.

    So In WCF I would ; make a DataContract [is kind of like a table] (ie table name Employee) then you would make a variable for information (ie: column  names ) and then I would make a dataMember for each of those(constructors.. get set) .

    [DataContract]
        public class Employee
        {
            private string fName;
            private string lName
            private string Department;
            private int Salary;
            
            [DataMember]
            public string fName
            {
                get { return fName; }
                set { fName = value; }
            }
    
             [DataMember]
            public string lName
            {
                get { return lName; }
                set { lName = value; }
            }
    
             [DataMember]
            public string Department
            {
                get { return Department; }
                set { Department = value; }
            }
            [DataMember]
            public int Salary
            {
                get { return Salary; }
                set { mSalary = value; }
            }
    

    Then witin my WCF I would have my database connectivity.

    In my metro app I use HttpClient to talk with my WCF. I serialize data that goes to the database. and anything I wanted to retrieve from the database i would deserialize. Correct?

    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Employee));
    Am I missing anything on either part?


    Thursday, September 6, 2012 6:41 PM
  • well if you have a wcf service server side (insteadd of the PHP) its easier to create the datacontract and servicecontracts and then generate the service client in your metro app

    have a look here:

    http://msdn.microsoft.com/en-us/library/bb386386.aspx

    • Edited by Dave SmitsMVP Thursday, September 6, 2012 6:50 PM
    • Marked as answer by kokoroastrum Friday, September 7, 2012 2:09 PM
    Thursday, September 6, 2012 6:48 PM
  • I thought it wasn't 'metro' anymore it was 'modern'?
    Thursday, September 6, 2012 8:34 PM
  • no clue what it is.. i'm lost in that discussion/. and this forum still called metro style apps :) but shall we focus on the question?
    Thursday, September 6, 2012 8:44 PM
  • alright thanks. Makes more sense with the code to build upon.

    and I think it was metro as the 'internal' name (because it's trademarked:P) so they switched it to modern UI instead... Tho the title seems more like a description than an actual product lol... I call it MUI sometimes, but if you need google you search to 'metro' apps... confusing indeed

    Friday, September 7, 2012 2:15 PM