WCF and null reference in Message contract

Discussion in 'ASP .Net Web Services' started by Scott Holman, Mar 15, 2007.

  1. Scott Holman

    Scott Holman Guest

    I have defined a message contract (MsgRespData) and data
    contract(DataResponse) listed below. The data contract has two fields
    (System.String and System.Data.Dataset) and the message contract contains
    the data contract. The service contract has a single method that returns
    MsgRespData. When I test the service returning a instaniated DataSet in
    DataResponse everything is fine. However, when the DataSet is null I
    encounter the exception listed below. If I replace the DataSet in the
    DataResponse contract with my own serializable class and return a null
    reference the service works correctly.

    Any insights would be appreciated. Thanks

    **************************************************************************
    System.InvalidOperationException: No corresponding start element is open.
    Server stack trace:
    at System.Xml.XmlBaseReader.ReadEndElement()
    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.Call(String action,
    Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
    outs, TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannel.Call(String action,
    Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
    outs)
    at
    System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
    methodCall, ProxyOperationRuntime operation)
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
    message)

    ********************************************************************

    [MessageContract]
    public class MsgRespData
    {
    private WCFService1.DataContracts.DataResponse respDataField;

    [MessageBodyMember(Order = 0)]
    public WCFService1.DataContracts.DataResponse respData
    {
    get { return respDataField; }
    set { respDataField = value; }
    }

    }

    [DataContract(Namespace = "http://WCFService1.DataContracts/2007/03",
    Name = "DataResponse")]
    public partial class DataResponse
    {
    private MyClass DataCollectionField;
    private System.String RespTextField;

    [DataMember(EmitDefaultValue=true, IsRequired = false, Name =
    "DataCollection", Order = 0)]
    public MyClass DataCollection
    {
    get { return DataCollectionField; }
    set { DataCollectionField = value; }
    }
    [DataMember(IsRequired = false, Name = "RespText", Order = 1)]
    public System.String RespText
    {
    get { return RespTextField; }
    set { RespTextField = value; }
    }

    }
     
    Scott Holman, Mar 15, 2007
    #1
    1. Advertising

  2. Scott Holman

    Scott Holman Guest

    Previous post had incorrect definition of DataResponse:

    [DataContract(Namespace = "http://WCFService1.DataContracts/2007/03",
    Name = "DataResponse")]
    public partial class DataResponse
    {
    private System.Data.DataSet DataCollectionField;
    private System.String RespTextField;

    [DataMember(EmitDefaultValue=true, IsRequired = false, Name =
    "DataCollection", Order = 0)]
    public System.Data.DataSet DataCollection
    {
    get { return DataCollectionField; }
    set { DataCollectionField = value; }
    }
    [DataMember(IsRequired = false, Name = "RespText", Order = 1)]
    public System.String RespText
    {
    get { return RespTextField; }
    set { RespTextField = value; }
    }

    }


    "Scott Holman" <> wrote in message
    news:...
    >I have defined a message contract (MsgRespData) and data
    >contract(DataResponse) listed below. The data contract has two fields
    >(System.String and System.Data.Dataset) and the message contract contains
    >the data contract. The service contract has a single method that returns
    >MsgRespData. When I test the service returning a instaniated DataSet in
    >DataResponse everything is fine. However, when the DataSet is null I
    >encounter the exception listed below. If I replace the DataSet in the
    >DataResponse contract with my own serializable class and return a null
    >reference the service works correctly.
    >
    > Any insights would be appreciated. Thanks
    >
    > **************************************************************************
    > System.InvalidOperationException: No corresponding start element is open.
    > Server stack trace:
    > at System.Xml.XmlBaseReader.ReadEndElement()
    > 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.Call(String action,
    > Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
    > outs, TimeSpan timeout)
    > at System.ServiceModel.Channels.ServiceChannel.Call(String action,
    > Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
    > outs)
    > at
    > System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
    > methodCall, ProxyOperationRuntime operation)
    > at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
    > message)
    >
    > ********************************************************************
    >
    > [MessageContract]
    > public class MsgRespData
    > {
    > private WCFService1.DataContracts.DataResponse respDataField;
    >
    > [MessageBodyMember(Order = 0)]
    > public WCFService1.DataContracts.DataResponse respData
    > {
    > get { return respDataField; }
    > set { respDataField = value; }
    > }
    >
    > }
    >
    > [DataContract(Namespace = "http://WCFService1.DataContracts/2007/03",
    > Name = "DataResponse")]
    > public partial class DataResponse
    > {
    > private MyClass DataCollectionField;
    > private System.String RespTextField;
    >
    > [DataMember(EmitDefaultValue=true, IsRequired = false, Name =
    > "DataCollection", Order = 0)]
    > public MyClass DataCollection
    > {
    > get { return DataCollectionField; }
    > set { DataCollectionField = value; }
    > }
    > [DataMember(IsRequired = false, Name = "RespText", Order = 1)]
    > public System.String RespText
    > {
    > get { return RespTextField; }
    > set { RespTextField = value; }
    > }
    >
    > }
    >
    >
     
    Scott Holman, Mar 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,709
    Mike Schilling
    Mar 29, 2006
  2. Specialist Verilog Engineers Roles
    Replies:
    0
    Views:
    472
    Specialist Verilog Engineers Roles
    Jun 27, 2007
  3. Simon
    Replies:
    0
    Views:
    1,026
    Simon
    Oct 13, 2009
  4. Cindy Lee
    Replies:
    1
    Views:
    2,129
    Mr. Arnold
    Mar 19, 2010
  5. James Holak

    WCF: Stop VS2008 generating message contracts

    James Holak, Jan 14, 2008, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    293
    James Holak
    Jan 14, 2008
Loading...

Share This Page