【发布时间】:2019-03-02 06:33:00
【问题描述】:
我有一个 WCF 服务和客户端网站来测试该服务。 WCF 服务没有获取对象的值。我已经在网上搜索并修改了我的代码。不过我还没有解决。有人会帮助我吗。提前致谢。
有我的服务:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "BookInfo/")]
BookingResult Booking(BookInfo bookInfo);
public BookingResult Booking(BookInfo bookInfo)
{
BookingResult result = new BookingResult();
if (bookInfo.Name == null)
{
result.isSucceed = false;
}
else
{
result.isSucceed = true;
}
return result;
}
我的网站上有调用服务的方法。
using Booking; //this is WCF service reference
private string callService(BookInfo input)
{
string serviceUrl = "http://localhost:1599026/Booking.svc/BookInfo/";
string stringPayload = "{\"bookInfo\":[" +JsonConvert.SerializeObject(input) +"]}";
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
client.Encoding = Encoding.UTF8;
string rtn = client.UploadString(serviceUrl,"POST", stringPayload);
return rtn;
}
【问题讨论】: