我已经创建了一个包含所有CRUD操作的WCF REST服务。我在PUT和POST方法中遇到问题。
此处是我的所有方法的界面代码。 IEventService
我在UWP应用程序中使用此服务。我创建了一个Helper方法,它从我的WCF REST服务访问该方法。
public static async void AddNewEvent()
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:59093/EventService.svc/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Models.Event eventInfo = new Models.Event()
{
EventId = 8,
Name = "C",
ETime = DateTime.Now.Date,
STime = DateTime.Now.Date.AddDays(2),
Cost = 980,
Description = "REST.",
Slots = 2
};
var json = JsonConvert.SerializeObject(eventInfo);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("NewEvent", content);
if (response.IsSuccessStatusCode)
{
}
}
}
当我尝试通过在Helper方法中传递内容来使用PUT和POST方法时,我得到如下代码:
我在发送web api时发送数据,但它给出了错误,即对象引用未设置为对象的实例。请帮我解决一下这个。感谢。