none
WCF to WSDL to JSON RRS feed

  • Question

  • i make a WCF Services which gives a wsdl file soap



    What i want i want a JSON in returning of my method call from Windows phone to My service . and JSON should be clean like other means to say like graph.api.facebook etc is it possible which is the correct way for doing this.

    Thanks in Advance :)


    MobinYaqoob

    Thursday, November 19, 2015 3:15 PM

Answers

  • Thankyou so much for all information you give. your all links are very use full to me. i mean great links you share with me. Thanks a lot Stefan Hoffmann
    :)

    but for my problem is wcf to json i personally found this link help ful :

    and i will try to follow these usefull information and keep in mind while writing my code

    http://mikesknowledgebase.azurewebsites.net/pages/Services/WebServices-Page1.htm

    i means that's i want to try and it helps :)


    MobinYaqoob

    • Marked as answer by MobinYaqoob Friday, November 20, 2015 2:24 PM
    Friday, November 20, 2015 2:24 PM

All replies

  • WCF means SOAP per default. And SOAP means XML. So in short:

    When you want to consume JSON, you should evaluate Web API to create RESTful services. Otherwise you can create WCF RESTful service returning service: How to create a JSON WCF RESTful Service in 60 seconds

    • Marked as answer by MobinYaqoob Friday, November 20, 2015 5:49 AM
    • Unmarked as answer by MobinYaqoob Friday, November 20, 2015 7:56 AM
    Thursday, November 19, 2015 3:28 PM
  • Sorry for marking it as answer but it is different and don't work for me .

    may be it's my mistake that i should elaborate my question.

    so here is the detail :

    1. I Create a WCF Service Application.

    2. Then i method in service.cs

    public string CheckUserExitsInDB(string username,string password)
            {
               
                //string re = null;
                try
                {
                    Authentication();
                    //con.Open();
                    //MySqlCommand command = con.CreateCommand();
                    string insertQuery = " SELECT id from authentication WHERE email ='"+username+"'"+"AND password='"+password+"'";
                    //SELECT CustomerID,CustomerName FROM Customers WHERE contactname='Maria Anders' AND Address='Obere Str. 57';
                    MySqlCommand command = new MySqlCommand(insertQuery,con);
                    MySqlDataReader reader = command.ExecuteReader();
                    //command.CommandText = "SELECT id from authentication WHERE email ='" + username + "'";
                    //command.ExecuteNonQuery();
                    string re = null;
                    //LinkedList<string> ll_email = new LinkedList<string>();
                    while (reader.Read())
                    {
                         re = reader.GetString(0);
                        //for (int i = 0; i < reader.FieldCount; i++)
                        //{
                        //    ll_email.AddLast(reader.GetValue(i).ToString());
                        //}
                    }
                    //return re;
                    return re;
                }
                catch (Exception ex)
                {
                    return ex.ToString();
                }
                finally
                {
                    con.Close();
                    
                }
             
            }

    it fetches the row which matches the username and password .

    and give us the id of that row .

    i want when i hit a url with username and password it give the id in json.

    Or What is the better way

    I want to make a user login.

    Thanks in Advance :)


    MobinYaqoob

    Friday, November 20, 2015 8:24 AM
  • OMG!

    Ever thought about security? Your piece of code is terrible. SQL Injection (How to: Execute a Parameterized Query). Side channel data loss. Exception swallowing (Exception Handling). Incorrect handling of unmanaged resources (using Statement (C# Reference), IDisposable Interface). Cluttered, dead code (Rule 12: 13 Tips to Comment Your Code, don't using any kind of code repository?). Weird coupling (Authentication() does what?, using external unmanaged resources (con), but freeing it). Storing passwords instead of hashes (Salted Password Hashing - Doing it Right, Storing Passwords - done right!, Password salt and hashing in C# ). Using wrong naming (insertQuery, which does a SELECT). Using string instead of SecureString for the password. And why don't you use the built-in mechanisms?

    Authentication and Authorization in WCF Services - Part 1

    WCF Authentication: Custom Username and Password Validator

    And for your method, start with

    public string RetrieveUserID(string username, SecureString password)
    {
        const string SQL = "SELECT id FROM authentication WHERE email = @username AND password = @password;";
        string result = null;            
        using (MySqlConnection connection = CreateConnection())
        {
            using (MySqlCommand command = new MySqlCommand(SQL, connection))
            {
                command.Parameters.AddWithValue("@username", username);
                command.Parameters.AddWithValue("@password", password);
                result = (string)command.ExecuteScalar();
            }
        }
    
        return result;
    }
    
    private MySqlConnection CreateConnection()
    {
        throw new NotImplementedException();
    }


    Friday, November 20, 2015 9:32 AM
  • Thankyou so much for all information you give. your all links are very use full to me. i mean great links you share with me. Thanks a lot Stefan Hoffmann
    :)

    but for my problem is wcf to json i personally found this link help ful :

    and i will try to follow these usefull information and keep in mind while writing my code

    http://mikesknowledgebase.azurewebsites.net/pages/Services/WebServices-Page1.htm

    i means that's i want to try and it helps :)


    MobinYaqoob

    • Marked as answer by MobinYaqoob Friday, November 20, 2015 2:24 PM
    Friday, November 20, 2015 2:24 PM