【发布时间】:2011-02-27 00:01:51
【问题描述】:
我正在尝试使用 jQuery 将数据从客户端应用程序发送到基于 WCF REST 入门工具包的 REST WCF 服务。
这是我目前所拥有的。
服务定义:
[WebHelp(Comment = "Save PropertyValues to the database")]
[WebInvoke(Method = "POST", UriTemplate = "PropertyValues_Save",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
public bool PropertyValues_Save(Guid assetId,
Dictionary<Guid, string> newValues) {
// ...
}
来自客户端的调用:
$.ajax({
url:SVC_PROPERTYVALUES_SAVE,
type: "POST",
contentType: "application/json; charset=utf-8",
data: jsonData,
dataType: "json",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + ' ' + errorThrown);
},
success: function(data) {
if (data) {
alert('Values saved'); $("#confirmSubmit").dialog('close');
}
else {
alert('Values failed to save'); $("#confirmSubmit").dialog('close');
}
}
});
传递的 JSON 示例:
{
"assetId": "d70714c3-e403-4cc5-b8a9-9713d05b2ee0",
"newValues": [
{
"key": "bd01aa88-b48d-47c7-8d3f-eadf47a46680",
"value": "0e9fdf34-2d12-4639-8d70-19b88e753ab1"
},
{
"key": "06e8eda2-a004-450e-90ab-64df357013cf",
"value": "1d490aec-f40e-47d5-865c-07fe9624f955"
}
]
}
web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
<appSettings>
...
</appSettings>
</configuration>
我在虚拟目录上使用 Windows 身份验证,匿名访问被禁用。当我调用 GET 操作时,一切都很好。此代码提示浏览器登录。当我输入我的凭据时,我只是在浏览器中收到一条警报,上面写着“错误未定义”。
即使您无法解决我的具体错误,您是否看到任何看起来不对劲的地方?
我几乎整天都在为此苦恼。
提前致谢。
【问题讨论】:
标签: wcf json dictionary