I got error when try execute this wcf code
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IService1 ----> System.Runtime.Serialization.InvalidDataContractException: Method 'MyClassLibrary.MyDataTable.GetSchema()' must return a schema with a valid Id. at System.Runtime.Serialization.SchemaExporter.InvokeGetSchemaMethod(Type clrType, XmlSchemaSet schemas, XmlQualifiedName stableName) 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.XsdDataContract开发者_运维技巧Exporter.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) .... ... ....
Custom datatable
Public Class MyDataTable
Inherits DataTable
Public Sub New()
End Sub
End Class
My WCF Interface
<ServiceContract()> _
Public Interface IService1
<OperationContract()> _
Function TestDatatable(ByVal MyDT As MyDataTable) As Boolean
End Interface
Implementation
Public Class Service1
Implements IService1
Public Function TestDatatable(ByVal MyDT As MyClassLibrary.MyDataTable) As Boolean Implements IService1.TestDatatable
Return MyDT.TableName = "MyTable"
End Function
End Class
Note: When just using datatable its ok but not my custom datatable.
What need to be added do I can serialize my custom datatable. I able to serialize my other object but not this class.
Instead of manually deriving from DataTable
I'd create a typed data set using Visual Studio's data set designer. They are much easier to work with.
Implementation of GetSchema method in DataTable looks like
protected virtual XmlSchema GetSchema()
{
if (this.GetType() == typeof (DataTable))
return (XmlSchema) null;
So that you may override this method in the following way
protected override XmlSchema GetSchema()
{
return null;
}
This will resolve serialization issue.
精彩评论