3

所以我有以下服务:

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 是否需要任何配置?

编辑:找到解决方案,我是白痴。上次我更正提琴手请求以反映正确的身体包裹时,我忘记将身体尺寸从 25 更改为正确的 38。感谢您的快速回复!

4

0 回答 0