WCF and null reference in Message contract

S

Scott Holman

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; }
}

}
 
S

Scott Holman

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 said:
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; }
}

}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top