所以我有以下服务:
public interface IService1
{
[OperationContract, WebGet(UriTemplate = "/getStuff?stuff={stuff}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
List<Row> getdTable(string stuff);
[OperationContract, WebInvoke(UriTemplate = "/log", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST")]
void insertLog(Log[] log);
[OperationContract, WebInvoke(UriTemplate = "/testPost", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST")]
void testPost(TwoStrings testPost);
}
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[DataContract]
public class TwoStrings
{
[DataMember]
public string one { get; set; }
[DataMember]
public string two { get; set; }
}
WebGet就像一个魅力,但我不能让任何webinvoke方法实际工作。 我正在使用fiddler测试它,使用以下POST:
POST http://localhost:50051/Service1.svc/testPost HTTP/1.1
Host: localhost:50051
User-Agent: Fiddler
Content-Type: application/json; charset=utf-8
Content-Length: 25
{"testPost":{"one":"test1","two":"test2"}}
我得到的回应是:
HTTP/1.1 400 Bad Request
我在这里不知所措,我在JSON机身上尝试了几种不同的格式无济于事。 JSON格式正确吗?是否需要进行POST配置?
编辑:发现解决方案,我是IDIOT。我最后一次纠正了小提琴请求以反映正确的身体包裹,我忘了将身体尺寸从25改为正确的38。 感谢您的快速回复!