1

每次我的 WCF 主机应用程序池启动时,对其进行第一次 WCF 调用的客户端总是抛出“System.Xml.XmlException:有多个根元素”所有后续调用都可以正常工作。

此异常发生在 WCF 请求的使用者/客户端。我已经针对完整的 WCF 客户端和 Silverlight 客户端对此进行了测试。它使用的是 basicHttpBinding,没有安全性,并且 aspnetCompatabilityMode = true

如果应用程序池保持活动状态,这没什么大不了的,但是由于缺乏活动,它会关闭,并且在重新启动时再次发生错误。

我还应该提到,应用程序池有时会从非 WCF 请求开始到另一个页面。但是还是第一次调用WCF,还是会在客户端抛出这个异常。

有人见过这个吗?如有必要,我可以提供更多详细信息。

谢谢

4

2 回答 2

3

Okay, after researching these options, I figured out what caused the issue. Ultimately, inheritance and having both attributes, serializable and DataContract, in the data being exchanged did not make a difference with deserializing the response.

The real meat of the issue was in my configuration. Earlier I was playing with Streaming messages. I left my host transferMode set to Streaming and my client was set to Buffered. In silverlight, that's my only option. So the serialization problem happened because the message was being chunked. I noticed this after tracing a few calls.

So easy peasy fix. Switch transferMode to Buffered. I'm going to setup a separate endpoint for streaming and play with that another time. I don't need to stream the CRUD services.

Thanks for everyone's input.

-Nathan

于 2009-07-17T00:48:46.900 回答
0

在我看来,这听起来像是一个序列化问题。我会调查你是如何构建你的 DataContracts 的——你使用的是 DataContracts 而不是 XML 序列化属性,对吧?

编辑:根据我们的评论,我将为您的重构提出建议:

[DataContract] 
public class ImageEffectExcludeParamRequest
{ 
    [DataMember] 
    public string ImageID { get; set; } 

    [DataMember] 
    public int EffectID { get; set; } 

    [DataMember]
    public ResponseInfo AdditionalInfo { get; set; }
}


[DataContract] 
public class ResponseInfo 
{ 
    [DataMember] 
    public Enums.ServiceResponse.Status Status { get; set; } 

    [DataMember] 
    public string Message { get; set; } 
}

使用组合而不是继承应该可以解决您的问题。

于 2009-07-16T14:46:51.493 回答