c# - WCF service throw Exception for some types -


i created wcf service.in data contract have 2 attributes lets say:

[datamember] private user objuser; 

and

[datamember] private tempclass objtemp; 

i have , set property both attributes. in implementation class, have object of datacontract class... lets say. objdata.

when assign

objdata.objtemp=(function return objtemp); 

the service work fine. but, when assign.

objdata.objuser=(function return objuser) 

it throws following error:

the underlying connection closed: connection closed unexpectedly.

when comment

objdata.objuser=(function return objuser) 

it works fine again.

when inspect code inside user class, found 1 property creating problem. when change property property works fine too; not know why property creating problem.

the property this:

public ipaddress ip { get; set; } 

now ipadress class contains constructor, , , set ip variable. in get, returns ip variable.

in set checks condition , assign value ip variable. if condition fails, throws exception. can explain problem be?

i checked thing.

if remove [datamember] attribute private user objuser; works fine; if put [datamember] generates same error.

any suggestions?

you find objuser not serializable. more info read this: msdn: using data contracts

to quote short snippet of that:

all .net framework primitive types, such integers , strings, types treated primitives, such datetime , xmlelement, can serialized no other preparation , considered having default data contracts.... new complex types create must have data contract defined them serializable.

you consider using service trace viewer tool microsoft track down exact problem having.


edit:

if system.net.ipaddress object talking about, marked [serializable], doesn't have default parameterless constructor, 1 of requirements necessary when using datacontractserializer (which used serialize data objects on wcf boundary). may want ensure if of custom objects used in wcf calls contain further custom objects (in properties, ipaddress) decorated knowntype attribute.

so, solution can either write own ipaddress class plays nice datacontractserializer, or switch using xmlserializer in wcf calls.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -