Error using System.Object

Topics: General Discussion Forum, Service Factory Modeling Edition Forum
Apr 8, 2008 at 6:43 PM
Hi,

I am currently facing this error:
/*
There was an error while trying to serialize parameter http://wstest1:UBLPO. The InnerException message was 'Type 'UBLPurchaseOrder.OrderType' with data contract name 'OrderType:http://schemas.datacontract.org/2004/07/UBLPurchaseOrder' 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.*/

It happens in the WCF web service, when I try to return a System.Object, to which I have assigned an object of type 'UBL_PurchaseOrder.OrderType' .

I am trying this approach instead of using the Xsd approach, since using the UBL schema is not supported by the WCF datacontract serializer.

Thanks and nay help is muhc appreciated..
Apr 8, 2008 at 6:49 PM
Try adding to that operation the attribute KnownType(typeof(UBLPurchaseOrder.OrderType)) so your contract will know how to deal with this type.
Apr 9, 2008 at 3:55 PM

charlyfriend wrote:
Try adding to that operation the attribute KnownType(typeof(UBLPurchaseOrder.OrderType)) so your contract will know how to deal with this type.


Hi CharlyFriend,

Definitely you are a good friend! it worked thanks! I had to make a change because, honestly, I couldnt find the exact place where to write the KnownType(typeof(UBLPurchaseOrder.OrderType)) . Finally my sollution looks like this:

namespace WCFService1.ServiceImplementation
{
WCF::ServiceKnownType(typeof(UBL_PurchaseOrder.OrderType))
public partial class MyService : MyServiceBase
{
public override WCFService1.MessageContracts.GetPOListResponse GetPOList(WCFService1.MessageContracts.GetPOListRequest request)
{
WCFService1.MessageContracts.GetPOListResponse resp = new WCFService1.MessageContracts.GetPOListResponse();
resp.POList = new WCFService1.DataContracts.POListType();
WCFService1.DataContracts.POListEntryType entry = new WCFService1.DataContracts.POListEntryType();
entry.PONo = "Pono1";
.....


It didnt allow me to write the KnownType(typeof.... thing just above the overriden action. It did not even show the KnownType as an available method. Instead, the ServiceKnownType was , I used it and then it worked.

Thanks again.




Apr 6, 2010 at 7:40 PM

This was very helpful to me, but I had to make the changes to the actual generated code from my model. How do I define well know types for my data contraccts in the modeler. The "Browse and Select .NET types" is pretty limiting. If I can get it to work in code shouldn't I be able to account for it in the model. If I update my model and regenerate code I loose any physical changes I previously made in the generated code. Any ides? Anyone?

Thanks.

Apr 7, 2010 at 3:59 AM

Hi Swart,

You may find some of the two first posts here as likely scenarios for this: http://servicefactory.codeplex.com/Thread/View.aspx?ThreadId=23616