WCF服务多种方法调用一个Ajax请求 [英] WCF service multiple method calls one ajax request

查看:156
本文介绍了WCF服务多种方法调用一个Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始提问之前,请先了解一些背景信息.我有通过jquery.ajax调用的WCF服务.我可以在控制台窗口中看到并使用其他工具验证该请求仅发生一次.

Before I begin my question a little background info. I have the WCF service that is being called via jquery.ajax. I can see in the console window and verify with other tools that the request is happening only once.

在服务器端,我看到该方法精确触发了3次.这怎么可能呢?在服务上,我使用以下属性和签名进行修饰

On the server side, I see the method firing 3 times exactly. How could this happen? On the service I am decorating with the following attributes and signature

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public ResponseEnvelope AddToCart(Order[] Order)  //ResponseEnvelope
{
   .....
}

有趣的是,当我将响应从ResponseEnvelope更改为void时,效果很好.

The interesting thing is that when I change the response from ResponseEnvelope to void it works fine.

我怀疑这可能与我的DataContracts和对象层次结构有关,并且我正在对此进行测试.

I am suspecting this might have something to do with my DataContracts and object hierarchy and I am testing through that now.

感谢您的帮助.

推荐答案

我已经在休假,但是如果有任何帮助的人,这里是解决此问题的方法.该问题可能没有包含足够的信息来解决问题.

I've been on vacation but here is the answer to this problem in case it helps anyone down the line. The question likely didn't contain enough information to solve the problem.

事实证明,问题出在串行器内部.在DataContract中将对象用作类型会产生我最终能够捕获的错误.该错误消息实际上是关于如何解决该问题的非常明确的信息,因此我将保留它.

As it turns out the problem is in inside the serializer. Using object as a type within the DataContract generated an error that I was eventually able to capture. The error message was actually very explicit about how to solve the issue so I will leave it at that.

将任何静态未知的类型添加到已知类型的列表中-例如,通过使用KnownTypeAttribute属性或将它们添加到传递给DataContractSerializer的已知类型的列表中. 在System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract,XmlWriterDelegator xmlWriter,Object obj,Boolean verifyKnownType,RuntimeTypeHandle声明为TypeHandle) 在System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.SerializeWithXsiType(XmlWriterDelegator xmlWriter,Object obj,RuntimeTypeHandle objectTypeHandle,Type objectType,Int32声明的TypeID,RuntimeTypeHandle的声明的TypeHandle,Type的声明的类型) ...

Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer. at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType) ...

这篇关于WCF服务多种方法调用一个Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆