各位晚上好!~
最近我在学习WCF,可是我的Entity类老序列化不过去。请大家帮忙给看看。谢谢Enitty类如下:
[Serializable]
public class S_UserBaseEntity : EntityBase
{
public S_UserBaseEntity()
{
_tableSchema = S_UserBaseTable.Current;
} #region 属性列表 public long lID
{
get { return Convert.ToInt64(GetData(S_UserBaseTable.C_lID)); }                                                                                                                                            
set { SetData(S_UserBaseTable.C_lID, value); }
}
public string sLoginID
{
get { return Convert.ToString(GetData(S_UserBaseTable.C_sLoginID)); }
set { SetData(S_UserBaseTable.C_sLoginID, value); }
}
#endregion
}它所调用的Table类如下:
 [Serializable]
public class S_UserBaseTable : TableInfo
{
public const string C_lID = "lID";
public const string C_sLoginID = "sLoginID";
public S_UserBaseTable()
{
_tableName ="S_UserBase";
} protected static S_UserBaseTable _current;
public static S_UserBaseTable Current
{
get
{
if (_current == null)
{
Initial();
}
return _current;
}
} private static void Initial()
{
_current = new S_UserBaseTable();
_current.Add(C_lID, new ColumnInfo(C_lID, true,DbType.Int64 ));
_current.Add(C_sLoginID, new ColumnInfo(C_sLoginID, false,DbType.String ));
}
}其中所继承的TableInfo,和EntityBase也都加上了可序列化标志。
经测试,这样序列化的对象可以保存到viewstate中。WCF部分代码如下:
WCF.Contract中代码如下:
[OperationContract]
        S_UserBaseEntity GetUserBaseEntity();client端调用方法如下:
public S_UserBaseEntity GetUserBaseEntity()
        {
            return this.Channel.GetUserBaseEntity();//就着出错了
        }调用的时候就是在上面这地方出错了
普通的Entity都能序列化过去。都能调用成功。唯独这么写的Entity却调用不成功。
报错如下:未处理的“System.ServiceModel.CommunicationException”类型的异常出现在 mscorlib.dll 中。其他信息: 套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“00:00:59.0460000”。

解决方案 »

  1.   

    对了,哪位愿意帮忙给调试看看的。请留下邮箱,我把Demo发过去。
    万分感谢
      

  2.   

    [email protected]抽时间帮你瞅瞅
      

  3.   

    已经给您发了。
    希望您抽空能看看。
    可以加我MSN:[email protected]
      

  4.   

    你的对象没有用datacontract标示,属性没有用datamemeber如果还不行,那就是你的类里包含了本身不能被序列化的对象
      

  5.   

    因为client和service都使用引用了该实体,所以不需要加datacontract了
    只要能序列化就行
    我加上的那个序列化标志是可以序列化的。因为如果new 一个实体对象,赋值后都能放到ViesState里面。ViewState就只能存放序列化后的东西。
    所以序列化了是比较肯定的。刚才我换成http方式来绑定。
    错误异常为:未处理 System.ServiceModel.CommunicationException
      Message="接收对 http://localhost:8080/AddTest 的  HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。有关详细信息,请参阅服务器日志。"
      Source="mscorlib"
      StackTrace:
        Server stack trace: 
           在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
           在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
           在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
           在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
           在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
           在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
        Exception rethrown at [0]: 
           在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
           在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
           在 WCF.Contract.IAddTest.GetUserBaseEntity()
           在 WCF.Client.AddTestClient.GetUserBaseEntity() 位置 G:\temp\新建文件夹\WCFFullDemo\WCF.Client\AddTestClient.cs:行号 40
           在 WCF.Client.Program.ShowResult() 位置 G:\temp\新建文件夹\WCFFullDemo\WCF.Client\Program.cs:行号 33
           在 WCF.Client.Program.Main(String[] args) 位置 G:\temp\新建文件夹\WCFFullDemo\WCF.Client\Program.cs:行号 14
           在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.Net.WebException
           Message="基础连接已经关闭: 接收时发生错误。"
           Source="System"
           StackTrace:
                在 System.Net.HttpWebRequest.GetResponse()
                在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           InnerException: System.IO.IOException
                Message="无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。"
                Source="System"
                StackTrace:
                     在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                     在 System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                     在 System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
                InnerException: System.Net.Sockets.SocketException
                     Message="远程主机强迫关闭了一个现有的连接。"
                     Source="System"
                     ErrorCode=10054
                     NativeErrorCode=10054
                     StackTrace:
                          在 System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                          在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                     InnerException: 
    我觉得是我实体里面的GetData()这个方法可能再赋值的时候试图调用service的东西,所以被远程主机强迫关闭了
    我只是初步这么认为的,但是不知道怎么解决
    希望大家帮忙给看看
    谢谢 啦
      

  6.   

    标记DataContract的目的,是让wcf使用它特有的序列化方式来序列,你只标记serializable的话,它只会调用传统的序列化方式,无论是速度还是对资源,都比不上使用它本身提供的序列化方式,它使用datacontractserialer来序列化,你可以看下它的源代码,对于有datacontract标示和没有,是使用截然不同的序列化方式,你用serializable标示,就是走的所谓deep serialize,如果你用datacontract和datameber,它只会序列化你用datameber标示了的属性。之所谓序列化不了,估计你的对象中有不支持序列化的属性,而你没有把它排除掉。
      

  7.   

    大哥您邮箱多少???
    还在吗???
    我发份Demo给您
    希望您能帮忙给看看行吗
      

  8.   

    请假下大家,要传输的实体ProfileInfo里面有个子实体List<JobInfo>,但是传输过去后变成了JobInfo[]。有没有什么办法可以使它还是List<JobInfo>  ?
      

  9.   

    添加服务引用时,“高级”设置可以指定集合类型。
    我也有WCF序列化问题
    http://topic.csdn.net/u/20100406/11/bec266ee-6ec7-440e-9d64-642a0e77530f.html