ASP.Net Web Service Error: Method Not Allowed

Last Reply 4 months ago By nauna

Posted 4 months ago

hello,

I have project and in it i have a file service1.svc, i am trying to insert data using http method but it is giving me error method not allowed. 

i am using below code to insert data when i run it in browser with following URI 

http://localhost:5826/service1.svc/UserInsert/serviceuser/abc/service@gmail.com

[WebInvoke(UriTemplate = "/UserInsert/{UserName}/{Password}/{Email}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public string message { get; set; }
public void userinsert(string UserName, string Password, string Email)
{ 
    int userId = 0;
    string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("Insert_User"))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Username", UserName.Trim());
                cmd.Parameters.AddWithValue("@Password", this.Encrypt(Password.Trim()));
                cmd.Parameters.AddWithValue("@Email", Email.Trim());
 
                cmd.Connection = con;
                con.Open();
                userId = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
            }
        }
 
        switch (userId)
        {
        case -1:
            message = "Username already exists.Please choose a different username.";
            break;
        case -2:
            message = "Supplied email address has already been used.";
            break;
        default: 
            message = "success."; 
            break;
        } 
    }
}

it gives me error method not allow 

Please advice

Posted 4 months ago Modified on 4 months ago

Posted 4 months ago

its working now i was missing Method tag in the code

thanks for your help

[WebInvoke(Method = "POST", UriTemplate = "/UserInsert/{UserName}/{Password}/{Email}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]