我遇到了一个大问题,当我升级Silverlight& Web项目分别为版本4。
由于这样做,我的所有WCF服务都失败,并显示以下错误消息:
反序列化Anyboat.Admin.UserService.User类型的对象时出错。意外的文件结束。以下元素未关闭:LastName,AuthenticateUserResult,AuthenticateUserResponse,Body,Envelope。
StackTrace是:
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at Anyboat.Admin.UserService.UserServiceClient.UserServiceClientChannel.EndAuthenticateUser(IAsyncResult result)
at Anyboat.Admin.UserService.UserServiceClient.Anyboat.Admin.UserService.UserService.EndAuthenticateUser(IAsyncResult result)
at Anyboat.Admin.UserService.UserServiceClient.OnEndAuthenticateUser(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
我在响应消息的SilverlightFaultBehaviour中放了一个断点,这是我回来的Envelope响应。请注意 * “\ r \ n”*
之间的回车符"<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">\r\n <s:Header>\r\n <a:Action s:mustUnderstand=\"1\">urn:UserService/AuthenticateUserResponse</a:Action>\r\n <a:RelatesTo>urn:uuid:07cc1361-c74c-4449-b423-e982d2ac8e05</a:RelatesTo>\r\n </s:Header>\r\n <s:Body>\r\n <AuthenticateUserResponse>\r\n <AuthenticateUserResult xmlns:d4p1=\"http://schemas.datacontract.org/2004/07/AnyBoat.Web.Classes.DataObjects\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <d4p1:Active>true</d4p1:Active>\r\n <d4p1:EmailAddress>robbie@robbietapping.com.au</d4p1:EmailAddress>\r\n <d4p1:FirstName>Robbie</d4p1:FirstName>\r\n <d4p1:IsAdministrator i:nil=\"true\" />\r\n <d4p1:LastName>Tapping</d4p1:LastName>\r\n <d4p1:Password>xxxxxxxxx</d4p1:Password>\r\n <d4p1:UserID>2</d4p1:UserID>\r\n <d4p1:UserName>robbietapping</d4p1:UserName>\r\n </AuthenticateUserResult>\r\n </AuthenticateUserR
esponse>\r\n </s:Body>\r\n</s:Envelope>"
任何人都可以告诉我,如果有这种情况,我将我的VS2010升级到SP1,这已经开始显现。
非常感谢任何信息或答案。
由于
修改 的
发生错误的代码是:
public Anyboat.Admin.UserService.User EndAuthenticateUser(System.IAsyncResult result) {
object[] _args = new object[0];
Anyboat.Admin.UserService.User _result = ((Anyboat.Admin.UserService.User)(base.EndInvoke("AuthenticateUser", _args, result)));
return _result;
}
答案 0 :(得分:1)
您在服务方使用哪种序列化类型?我很确定你使用了一些自定义序列化。 “\ r \ n”问题非常常见,当您尝试反序列化从服务中收到的格式不正确的xml时会出现问题。
所以我看到两种方式: