c# - ServiceKnownType client side issue -


server side:

service details:

[serviceknowntype("getknowntypes", typeof(helper))] [servicecontract] public interface iappconfigurationmanager {     [operationcontract]     object changeobjectproperty(object mycustomobject); } 

implementation:

public class appconfigurationmanager : iappconfigurationmanager {     public object changeobjectproperty(object mycustomobject)     {         foreach (type type in globals.mycustomtypes)         {             if (type == mycustomobject.gettype())             {                 foreach (propertyinfo property in mycustomobject.gettype().getproperties())                 {                     if(property.name == "id")                     {                         int oldvalue = convert.toint32(property.getvalue(mycustomobject));                         property.setvalue(mycustomobject, oldvalue + 1);                         break;                     };                 };                                 }         }          return mycustomobject;     } } 

helper class used collecting of knowntypes:

public static class helper {     public static ienumerable<type> getknowntypes(icustomattributeprovider provider)     {         globals.mycustomtypes = new list<type>();          system.collections.generic.list<system.type> knowntypes =             new system.collections.generic.list<system.type>();          assembly assembly = assembly.loadfrom(@"d:\wcf\runtimemanagement\bin\debug\runtimemanagement.dll");          foreach (type type in assembly.gettypes())         {             if (type.name.contains("customer") || type.name.contains("account"))             {                 knowntypes.add(type);                 globals.mycustomtypes.add(type);             };         };          return knowntypes;     } } 

classes:

[datacontract] public class customer  {     [datamember]     public int id { get; set; }      [datamember]     public string name { get; set; } }  [datacontract] public class account {     [datamember]     public int id { get; set; }      [datamember]     public string name { get; set; }      [datamember]     public customer accountowner { get; set; } } 

client side:

before invoking service, trying register knowntypes @ client side also:

private void fmmain_load(object sender, eventargs e) {     mycustomtypes = new list<type>();      assembly assembly = assembly.loadfrom(@"d:\wcf\runtimemanagement\bin\debug\runtimemanagement.dll");      foreach (type type in assembly.gettypes())     {         if (type.name.contains("customer") || type.name.contains("account"))         {             mycustomtypes.add(type);              if (type.name == "customer")             {                 customertype = type;             };              foreach (var operation in globals.appconfigmgrclient.endpoint.contract.operations)             {                 operation.knowntypes.add(type);             };         };     };      object mycustomerobject = activator.createinstance(customertype);      foreach (propertyinfo property in mycustomerobject.gettype().getproperties())     {         if (property.name == "id")         {             property.setvalue(mycustomerobject, 111);             break;         };     };      mycustomerobject = globals.appconfigmgrclient.changeobjectproperty(mycustomerobject);      foreach (propertyinfo property in mycustomerobject.gettype().getproperties())     {         if (property.name == "id")         {             debug.writeline(property.getvalue(mycustomerobject).tostring());             break;         };     }; } 

got error here:

mycustomerobject = globals.appconfigmgrclient.changeobjectproperty((runtimemanagement.catalogmanagement.customer)mycustomerobject); 

the formatter threw exception while trying deserialize message: there error while trying deserialize parameter http://tempuri.org/:mycustomobject. innerexception message 'element 'http://tempuri.org/:mycustomobject' contains data type maps name 'http://tempuri.org/:customer'. deserializer has no knowledge of type maps name. consider using datacontractresolver or add type corresponding 'customer' list of known types - example, using knowntypeattribute attribute or adding list of known types passed datacontractserializer.'. please see innerexception more details.

may long post, hope got idea trying here:

  1. adding customer , account classes serviceknowntype @ server side helper class.
  2. on load event of client side, trying register knowntypes same assembly customer , account exists.
  3. then creating instance of customer type, set it's id property 111, send operationcontract called changeobjectproperty. after successful execution, should increment id.

thanks time.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -