繁体   English   中英

WCF POST方法不起作用

[英]WCF POST Method is not working

我有一个WCF Web服务。 我想使用IIS将一些值发布到MS SQL数据库中。 GET方法有效。 但是我找不到我的POST方法有错误的地方。 有人帮我解决我的错误在哪里...谢谢。 这是我的代码...

    [OperationContract] //Interface
    [WebInvoke(Method = "POST", UriTemplate = "AddName", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
   int AddName(uName name);

     [DataContract]
   public class uName // a class in Interface
    {
        string name;
        [DataMember]
        public string setGetname
        {
            get { return name; }
            set { name = value; }
        }
    }

public int AddName(uName name) //My POST method in service class
    {

        int state = 0;
        SqlConnection connection = new SqlConnection(this.conStr);
        SqlCommand cmd = new SqlCommand();
        try
        {

            if (connection.State == System.Data.ConnectionState.Closed)
            {
                connection.Open();

            }
            cmd = new SqlCommand("Insert into Table_1(kolon1) values(@name)", connection);
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.AddWithValue("@name", name.setGetname);
            cmd.ExecuteReader();
            state = 1;

        }
        catch (Exception ex)
        {
            throw ex;

        }
        finally
        {
            connection.Close();
            cmd.Dispose();
        }


        return state;
    }

求助->我更改为“ BodyStyle = WebMessageBodyStyle.Bare”更改为“ BodyStyle = WebMessageBodyStyle.Wrapped”,它对我有用...谢谢...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM