How to accept parameters (including images) through a json web service and store it into a SQL Server database?

前端 未结 1 406
眼角桃花
眼角桃花 2021-01-26 12:57

I am getting an error:

Operation \'addUser\' in contract \'IService1\' has a UriTemplate that expects a parameter named \'PHONE_NO,DP,REG_ID\', but there

相关标签:
1条回答
  • 2021-01-26 13:39

    Your service can be something like this

    [ServiceContract]
    public class TestService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/AddUser/{phoneNo}/{regId}")]
        public string AddUser(string phoneNo, String regId, Stream image)
        {
           //Read your stream here
           return phoneNo + " " + regId;
        }
    }
    

    You can invoke it as:

    using (var client = new HttpClient())
    {
        var stream = new StreamContent(File.OpenRead(filename));
        var resp = await client.PostAsync("http://ip:port/TestService/AddUser/555111222/12345", stream);
        Console.WriteLine(resp.StatusCode.ToString());
    }
    
    0 讨论(0)
提交回复
热议问题