wcf rest : by using “BodyStyle = WebMessageBodyStyle.Wrapped”, I am not able to see object parameters in browser

被刻印的时光 ゝ 提交于 2020-03-06 05:53:12

问题


I have one method "CreateAccount" as mentioned below

[OperationContract]
[WebInvoke(UriTemplate = "CreateAccount", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public CreateAccountServiceResponse CreateAccount(AuthenticateApplication Application, ApplicationCustomer Customer, CustomerService Service, Option Options)
{
    // Some Implementation
}

If I am using

BodyStyle = WebMessageBodyStyle.Wrapped

then I am not able to find Request/Response parameters in browser. Instead it is showing like

Message    direction    Format  Body
Request     Unknown     Cannot infer schema. The Request body is wrapped.
Response    Unknown     Cannot infer schema. The Response body is wrapped

Can someone provide solution to this so that I can able to find request/response format.


回答1:


Hosting it on IIS instead of using visual studio in-build server did the trick for me.




回答2:


If you can wrap all of your inputs into a transport class, then you can remove the BodyStyle attribute, and everything will show up nicely.

ex.

public class CreateAccountServiceRequest {
    public AuthenticateApplication Application { get; set; }
    public ApplicationCustomer Customer { get; set; }
    public CustomerService Service { get; set; }
    public Option Options { get; set; }
}

[OperationContract]
[WebInvoke(UriTemplate = "CreateAccount", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public CreateAccountServiceResponse CreateAccount(CreateAccountServiceRequest request)
{
    // you can even reuse the existing method, as long as you don't expose it or change the UriTemplate so there's no conflict
    return CreateAccount(request.Application, request.Customer, request...
}


来源:https://stackoverflow.com/questions/24691444/wcf-rest-by-using-bodystyle-webmessagebodystyle-wrapped-i-am-not-able-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!