WCF service - OperationContract - string array
I'm building WCF service where one OperationContact should consume string array on input.
The POST request is build from jQuery with $.toJSON function and looks like
{"user":"77cae724-d5b3-412d-9499-2cfc175bf66f",
"data1":["ba3be5f2-c65d-4c21-86b1-829cad246746","604c53b1-1e24-42f7-8aba-93314eb0878e"],
"data2":"d15c3cf6-02c8-42f2-9753-ab2f5e10b21e",
"data3":["6449b58c-272c-4c98-a2fd-bd47ca248bb3","595fbefd-411e-40b1-afa1-f1f96495a8c1"]}
I 开发者_运维知识库create contract like:
[OperationContract]
bool function1(string userGuid, List<string> userOrganization, List<string> userCostUnit, List<string> userGroup);
and
[OperationContract]
bool function1(string userGuid, string[] userOrganization, string[] userCostUnit, string[] userGroup);
But nothing seems to work. I just get 500 Internal server error. Is problem with input data (json data)?
Can you please tell me how should function deceleration looks like, to makes this work.
Your contract doesn't match your JSON (for example, the JSON member is called "user" but you use "userGuid" in the contract).
You can do, for example:
[WebInvoke(RequestFormat = WebMessageFormat.Json)] [OperationContract] bool function1(Guid user, List data1, Guid data2, List data3);
You may also need to play with WebInvoke.BodyStyle to make this work - I think it should be "Wrapped".
精彩评论