簡體   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