$.ajax在IE中向wcf发送空参数
下面的接口定义了我的 WCF 服务。有时,调用此函数时“parameters”参数为空。其他时候则不然。
[ServiceContract]
public interface IContactRelationshipManager
{
[OperationContract]
[WebInvoke(
Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
void SaveActivityLogEntry(SaveActivityLogEntryParameters parameters);
}
这是我在 app.config 中的行为部分(我将其作为 Windows 服务运行)
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ContactRelationshipManagerBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
这是我的 javascript 调用:
$.ajax(
{
type: "POST",
cache: false,
contentType: "application/json",
url: serviceCallUrl,
data: JSON.stringify(params),
success: callbackHandler
});
JSON.stringify(params)
的结果是
“{”parameters”: {"ContactEmailAddress":"[电子邮件受保护]","LiasonsForContact":[25],"ActivityLogE ntry":{"日期":"/日期(1316634966273)/","LiasonFK":25,"TypeFK":1,"MethodFK":3,"描述":"tt","ContactFK":32}} }”
在实践中我在这里做错了什么吗?这在 Chrome 和 Firefox 中一直运行良好。我还在调试服务时使用 Fiddler 进行了测试,当 Fiddler 关闭时参数返回 null,而当 Fiddler 打开时参数返回 NOT null。
I have the interface below that defines my WCF services. Sometimes the 'parameters' parameter has been null when this is called. Other times it is not.
[ServiceContract]
public interface IContactRelationshipManager
{
[OperationContract]
[WebInvoke(
Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
void SaveActivityLogEntry(SaveActivityLogEntryParameters parameters);
}
Here is my behaviors section in the app.config (I'm running this as a windows service)
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ContactRelationshipManagerBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Here is my javascript call:
$.ajax(
{
type: "POST",
cache: false,
contentType: "application/json",
url: serviceCallUrl,
data: JSON.stringify(params),
success: callbackHandler
});
The result of JSON.stringify(params)
is
"{"parameters":{"ContactEmailAddress":"[email protected]","LiasonsForContact":[25],"ActivityLogEntry":{"Date":"/Date(1316634966273)/","LiasonFK":25,"TypeFK":1,"MethodFK":3,"Description":"tt","ContactFK":32}}}"
Is there anything that I'm doing wrong here in practice? This works fine all the time in chrome and firefox. I also just tested this with Fiddler while debugging the service and the parameter came back null with Fiddler closed and NOT null when Fiddler is open.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终使用了一堆不同的技术来让它工作,包括将流作为我的函数参数并使用 JSON.NET 在函数内将其序列化。那也没用。我终于找到了这个问题让我相信这是一个 NTLM 问题。我的网站在 IIS7 中使用 Windows 身份验证,并调用作为 Windows 服务托管的 WCF 服务。在服务器端,我将 webHttpBinding 的安全性更改为:
执行此操作后,Internet Explorer 中的一切正常
I ended up playing with a bunch of different techniques to get it to work including taking a stream as my function parameter and serializing it inside the function with JSON.NET. That didn't work either. I finally found this question which led me to believe that it was an NTLM problem. My website uses windows authentication in IIS7 and it calls a WCF service hosted as a windows service. On the server side I changed the security on my webHttpBinding to be as such:
After doing this everything works fine in Internet Explorer
例如,您可以使用 Fiddler 来嗅探实际发送的内容吗?我通常将数据对象直接传递给 $.ajax 并让它处理对象的序列化。我猜测字符串化的 JSON 编码不正确。
Can you use Fiddler, for example, to sniff what's actually being sent? I normally pass a data object directly to
$.ajax
and let it handle serializing the object. I have a guess that the stringified JSON is being encoded inappropriately.我实际上没有遇到任何问题,除了 ajax 调用中缺少一些属性之外,您拥有所有必需的配置。我不知道这是否有帮助。
I actually have not had any problems, you have all the required configurations except your missing a few properties in your ajax call. I don't know if this might help.