2009-10-15 43 views
0

我正在構建WCF服務,其中一個OperationContact應該在輸入上使用字符串數組。WCF服務 - OperationContract - 字符串數組

POST請求是從jQuery的建立與$ .toJSON功能,看起來像

{"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"]} 

我創建的合同,如:

[OperationContract] 
bool function1(string userGuid, List<string> userOrganization, List<string> userCostUnit, List<string> userGroup); 

[OperationContract] 
bool function1(string userGuid, string[] userOrganization, string[] userCostUnit, string[] userGroup); 

但似乎沒有任何工作。我剛剛得到500內部服務器錯誤。 輸入數據(json數據)有問題嗎?

你能告訴我應該如何減速功能看起來,使這項工作。

+0

檢查Web服務器日誌以獲取有關導致500響應的錯誤的更多信息。 – 2009-10-15 09:17:27

回答

2

您的合同與您的JSON不匹配(例如,JSON成員稱爲「用戶」,但您在合同中使用「userGuid」)。

可以做,例如:

[WebInvoke(RequestFormat = WebMessageFormat.Json)] [OperationContract的] 布爾功能1(GUID用戶,列表DATA1,DATA2的Guid,列表DATA3);

您可能還需要使用WebInvoke.BodyStyle來使這項工作 - 我認爲它應該是「包裝」。

+0

我從這個答案實現serializeObject函數http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery 但事實上它不適用於多個選擇項:( – AnzeR 2009-10-16 06:27:07