![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Using a WCF method that accepts an interface object I have a WCF service that exposes a generic method in which one of the parameters is an interface object (IObject - custom interface) and the service starts up just fine but when an object that inherits from IObject is passed, I get the following error: "System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/ bj. The InnerException messagewas 'Type 'WCFSharedLib.TestObject' with data contract name 'TestObject:http://schemas.datacontract.org/2004/07/WCFSharedLib' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: Type 'WCFSharedLib.TestObject' with data contract name 'TestObject:http://schemas.datacontract.org/2004/07/WCFSharedLib' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.\r\n at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyTyp e(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType)\r\n at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj)\r\n at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)\r\n at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)\r\n at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)\r\n at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)\r\n --- End of inner exception stack trace ---\r\n\r\nServer stack trace: \r\n at System.ServiceModel.Di spatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)\r\n at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)\r\n at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.On WriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.Message.WriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Security.SecurityAppliedMessage.WriteBodyToSignThenEncryptWithFragments(Stream stream, Boolean includeComments, String[] inclusivePrefixes, EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)\r\n at System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.ApplyBodySecurity(XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)\r\n at System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message mes sage, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)\r\n at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)\r\n at System.ServiceModel.Channels.MessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager)\r\n at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)\r\n at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)\r\n at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)\r\n at System.ServiceModel. Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)\r\n at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException reth rown at [0]: \r\n at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n at ISomeContract.Blah(Object obj)\r\n at SomeContractClient.Blah(Object obj) in C:\\Projects\\Junk\\WCFInterfaceTest\\WCFSharedLib\\WCFProxy.cs:line 106\r\n at WCFInterfaceTest.Form1.button1_Click(Object sender, EventArgs e) in C:\\Projects\\Junk\\WCFInterfaceTest\\WCFInterfaceTest\\Form1.cs:line 28" Here is my Interface definition: using System; using System.Collections.Generic; using System.Text; namespace WCFSharedLib { public interface IObject { string Name { get;set;} } } Here is the TestObject that inherits from IObject and it is also the object I'm passing to the WCF method: using System; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.Runtime.Serialization; namespace WCFSharedLib { [DataContract] public class TestObject:IObject, IExtensibleDataObject { private string _name; #region IObject Members [DataMember] public string Name { get { return _name; } set { _name = value; } } #endregion private ExtensionDataObject extensionDatavalue; #region IExtensibleDataObject Members public ExtensionDataObject ExtensionData { get { return extensionDatavalue; } set { extensionDatavalue = value; } } #endregion } } Here is the proxy client: using System; using System.Collections.Generic; using System.Text; namespace WCFSharedLib { public class WCFProxy: System.ServiceModel.ClientBase<ISomeContract>, ISomeContract { public WCFProxy() { } public WCFProxy(string endpointConfigurationName):base(endpointConfigurationName) { } public WCFProxy(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public WCFProxy(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public WCFProxy(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) { } #region ISomeContract Members public object Blah(object obj) { return base.Channel.Blah(obj); } #endregion } } And finally the method on the service that needs to be called: using System; using System.Collections.Generic; using System.Text; using System.Runtime.Serialization; namespace WCFHostingApp { public class SomeContract:ISomeContract { #region ISomeContract Members public object Blah(object obj) { WCFSharedLib.IObject temp = obj as WCFSharedLib.IObject; if (temp != null) { temp.Name = "Return Value: " + temp.Name; } return obj; } #endregion } } Anyone have any ideas?? |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Using a WCF method that accepts an interface object It is because the interfaces are not objects and in fact, they can not be serialized. I recommend to you, that use a serializable class derived from your interface, marking all their members as virtual or insert a base code if required. Then send the information by using the class in the services methods. When you obtain the info use the shared class and cast to the interface if necessary. Use the KnownTypeAttribute and ServiceKnownAttribute to mark as known the class. Regards, -- Ronald Ramirez Moran (aka DlanorOk) Personal Space: http://dlanorok.spaces.live.com Blog: http://ecuador.latindevelopers.net/blogs/dlanorok -- "Matthew Yost" <Matthew Yost@xxxxxx> wrote in message news:28E7CB75-90D5-4FE4-BAF7-0C1D8B10D9FC@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Using a WCF method that accepts an interface object I tried changing creating the base class that inherits from the interface IObject and I'm recieving the same exception each time. It's asking for known types. I've decorated the ISomeContract with the ServiceKnownType(typeof(DBObject))] attribute but i'm getting the following error: System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/ bj. The InnerException messagewas 'Type 'WCFSharedLib.TestObject' with data contract name 'TestObject:http://schemas.datacontract.org/2004/07/WCFSharedLib' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: Type 'WCFSharedLib.TestObject' with data contract name 'TestObject:http://schemas.datacontract.org/2004/07/WCFSharedLib' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.\r\n at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyTyp e(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType)\r\n at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj)\r\n at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)\r\n at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)\r\n at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)\r\n at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)\r\n --- End of inner exception stack trace ---\r\n\r\nServer stack trace: \r\n at System.ServiceModel.Di spatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)\r\n at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)\r\n at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)\r\n at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.On WriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.Message.WriteBodyContents(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Security.SecurityAppliedMessage.WriteBodyToSignThenEncryptWithFragments(Stream stream, Boolean includeComments, String[] inclusivePrefixes, EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)\r\n at System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.ApplyBodySecurity(XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)\r\n at System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)\r\n at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message mes sage, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)\r\n at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)\r\n at System.ServiceModel.Channels.MessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager)\r\n at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)\r\n at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)\r\n at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)\r\n at System.ServiceModel. Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)\r\n at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException reth rown at [0]: \r\n at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n at ISomeContract.Blah(DBObject obj)\r\n at SomeContractClient.Blah(DBObject obj) in C:\\Projects\\Junk\\WCFInterfaceTest\\WCFSharedLib\\WCFProxy.cs:line 213\r\n at WCFInterfaceTest.Form1.button1_Click(Object sender, EventArgs e) in C:\\Projects\\Junk\\WCFInterfaceTest\\WCFInterfaceTest\\Form1.cs:line 28" "Ronald Ramirez Moran" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Using a WCF method that accepts an interface object Ok, I found the answer to the problem. Turns out there is another serializer that is specialized for .NET to .NET communication using the WCF framework. It is called the NetDataContractSerializer. This serializer embeds the CLR Type in the Message so that it can be reconstructed on the other end. Here is the link to Avner Kashtan's blog which has the resolution and a link to Aaron Skonnard's blog who provides the attribute code to change the serializer from DataContractSerializer to NetDataContractSerializer. http://weblogs.asp.net/avnerk/archiv...erializer.aspx "Matthew Yost" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||
| Guest | Re: Using a WCF method that accepts an interface object The attributes ServiceKnownTypeAttribute and KnownTypeAttribute, must be applied to the Service Contract or ServiceImplementation. This is important, because the ServiceContract needs to know, how to serialize the messages. The class must be marked with a SerializableAttribute or DataContractAttribute attributes. Regards, -- Ronald Ramirez Moran (aka DlanorOk) Personal Space: http://dlanorok.spaces.live.com Blog: http://ecuador.latindevelopers.net/blogs/dlanorok -- "Matthew Yost" <MatthewYost@xxxxxx> wrote in message news:22B05DB6-8FC1-4909-8840-C8B6D20FD091@xxxxxx
| ||||||||||||||