Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Services (http://www.velocityreviews.com/forums/f64-asp-net-web-services.html)
-   -   WCF and null reference in Message contract (http://www.velocityreviews.com/forums/t786972-wcf-and-null-reference-in-message-contract.html)

Scott Holman 03-15-2007 01:58 PM

WCF and null reference in Message contract
 
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.ProxyOperationRunti me.AfterReply(ProxyRpc&
rpc)
at
System.ServiceModel.Channels.ServiceChannel.Handle Reply(ProxyOperationRuntime
operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(S tring action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(S tring action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
outs)
at
System.ServiceModel.Channels.ServiceChannelProxy.I nvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.I nvoke(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 03-15-2007 02:34 PM

Re: WCF and null reference in Message contract
 
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" <sholman@micros.com> wrote in message
news:uffQVowZHHA.5080@TK2MSFTNGP02.phx.gbl...
>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.ProxyOperationRunti me.AfterReply(ProxyRpc&
> rpc)
> at
> System.ServiceModel.Channels.ServiceChannel.Handle Reply(ProxyOperationRuntime
> operation, ProxyRpc& rpc)
> at System.ServiceModel.Channels.ServiceChannel.Call(S tring action,
> Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
> outs, TimeSpan timeout)
> at System.ServiceModel.Channels.ServiceChannel.Call(S tring action,
> Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
> outs)
> at
> System.ServiceModel.Channels.ServiceChannelProxy.I nvokeService(IMethodCallMessage
> methodCall, ProxyOperationRuntime operation)
> at System.ServiceModel.Channels.ServiceChannelProxy.I nvoke(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; }
> }
>
> }
>
>





All times are GMT. The time now is 11:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.