Inherited DataTable Serialization Problem in WCF

P

Paul

Any help would be greatly appreciated. I am using WCF (3.0) to provide a
services layer sitting on a server between a web server hosting ASP.NET 2.0
and SQL Server 2005. Some of these services provide a strongly typed
inherited DataTable for the ASP.NET application. Below is a partial listing
for one such DataTable. The code compiles successfully, and the service
which returns this DataTable seems to start normally.

A problem arises when using Add Service Reference in Visual Studio to
generate a client class to communicate with the service. The error below the
listing results when this generation is attempted. The most informative
message in the error seems to be: "Schema type
'Components.DataStructures:EquipmentList' returned by CLR type
'Components.DataStructures.EquipmentList' is not found in the XmlSchemaSet."
This says to me that in my class's GetXmlQualifiedName method, the schema for
the EquipmentList class is not being added to XmlSchemaSet passed in by
System.Runtime.Serialization.SchemaExporter.ExportXmlDataContract. To test
this, I created a simple Windows form with a button which executed the
following code:

XmlSchemaSet xss = new XmlSchemaSet();
EquipmentList.GetXmlQualifiedName(xss);

I checked the Count of xss.Schemas() before the static method on
EquipmentList was called, and it was 0 as expected. I checked it after this
method was executed and it was 1, also as expected. Further,
'Components.DataStructures:EquipmentList' did indeed exist in xss. In the
quick watch window, the QualifiedName of the only schema
is Components.DataStructures:EquipmentList. If it is there correctly when
executed with this simple test code, I would expect the schema to be properly
included in the XmlSchemaSet when called by
System.Runtime.Serialization.SchemaExporter. Why am I getting this error?
Am I misunderstanding the error, or is there something wrong in how I have
tested my code? Any help to resolve this error is appreciated.



INHERITED DATATABLE CODE

[XmlSchemaProvider("GetXmlQualifiedName")]
[Serializable]
public class EquipmentList : DataTable, IXmlSerializable
{
private static string _tableName = "EquipmentList";

private static string _namespace = "Components.DataStructures";

private static XmlSchema _schema;

. . .

public EquipmentList():base(_tableName, _namespace)
{
Initialize();
}

. . .

private void Initialize()
{
_equipmentId.AllowDBNull = false;
_name.AllowDBNull = false;
_category.AllowDBNull = false;
_type.AllowDBNull = false;

base.Columns.Add(_equipmentId);
base.Columns.Add(_name);
base.Columns.Add(_category);
base.Columns.Add(_type);
if (_schema == null)
{
_schema = base.GetSchema();
}
}

. . .

System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
{
throw new System.NotImplementedException();
}

void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
{
base.ReadXml(reader);
}

void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
{
base.WriteXml(writer, XmlWriteMode.DiffGram);
}


public static XmlQualifiedName GetXmlQualifiedName(XmlSchemaSet xss)
{
if (_schema == null)
{
// Schema is set when an instance is created, so create
// an instance if the schema is not yet set
EquipmentList list = new EquipmentList();
}

xss.Add(_schema);

return new XmlQualifiedName(_tableName, _schema.TargetNamespace);
}
}


SERVICE CLIENT GENERATION ERROR

Error: Cannot obtain Metadata from
net.tcp://localhost:52000/ComponentProviderListService/mex

If this is a Windows (R) Communication Foundation service to which you have
access, please check that you have enabled metadata publishing at the
specified address. For help enabling metadata publishing, please refer to
the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error
URI: net.tcp://localhost:52000/ComponentProviderListService/mex

Metadata contains a reference that cannot be resolved:
'net.tcp://localhost:52000/ComponentProviderListService/mex'.

<?xml version="1.0" encoding="utf-16"?><Fault
xmlns="http://www.w3.org/2003/05/soap-envelope"><Code><Value>Receiver</Value><Subcode><Value
xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</Value></Subcode></Code><Reason><Text
xml:lang="en-US">An exception was thrown in a call to a WSDL export
extension:
System.ServiceModel.Description.DataContractSerializerOperationBehavior
contract:
http://tempuri.org/:IComponentProviderListService</Text></Reason><Detail
xmlns:s="http://www.w3.org/2003/05/soap-envelope"><ExceptionDetail
xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink
i:nil="true"></HelpLink><InnerException><HelpLink
i:nil="true"></HelpLink><InnerException
i:nil="true"></InnerException><Message>Schema type
'Components.DataStructures:EquipmentList' returned by CLR type
'Components.DataStructures.EquipmentList' is not found in the
XmlSchemaSet.</Message><StackTrace> at
System.Runtime.Serialization.SchemaExporter.ExportXmlDataContract(XmlDataContract dataContract)
at
System.Runtime.Serialization.SchemaExporter.ExportDataContract(DataContract
dataContract)
at System.Runtime.Serialization.SchemaExporter.Export()
at System.Runtime.Serialization.XsdDataContractExporter.Export(Type type)
at
System.ServiceModel.Description.MessageContractExporter.ExportType(Type type,
String partName, String operationName, XmlSchemaType& xsdType)
at
System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32 messageIndex, Object state)
at
System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32
messageIndex, Object state)
at
System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
at
System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter
exporter, WsdlContractConversionContext contractContext)
at
System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext
contractContext, IWsdlExportExtension
extension)</StackTrace><Type>System.Runtime.Serialization.InvalidDataContractException</Type></InnerException><Message>An
exception was thrown in a call to a WSDL export extension:
System.ServiceModel.Description.DataContractSerializerOperationBehavior
contract:
http://tempuri.org/:IComponentProviderListService</Message><StackTrace> at
System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)
at
System.ServiceModel.Description.WsdlExporter.CallExportContract(WsdlContractConversionContext contractContext)
at
System.ServiceModel.Description.WsdlExporter.ExportContract(ContractDescription contract)
at
System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint
endpoint, XmlQualifiedName wsdlServiceQName)
at
System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1
endpoints, XmlQualifiedName wsdlServiceQName)
at
System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
at
System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
at
System.ServiceModel.Description.ServiceMetadataExtension.WSMexImpl.GatherMetadata(String dialect, String identifier)
at
System.ServiceModel.Description.ServiceMetadataExtension.WSMexImpl.Get(Message request)
at SyncInvokeGet(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object
instance, Object[] inputs, Object[]& outputs)
at
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
isOperationContextSet)</StackTrace><Type>System.InvalidOperationException</Type></ExceptionDetail></Detail></Fault>

Please excuse me for crossposting this here and (yesterday) on the
dotnet.xml group. I have not been able to find an MSDN Managed group for WCF
specifically and am guessing about the most appropriate group to post this to.
 

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

Top