Click here to Skip to main content
15,392,858 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I use httpwebrequest to call wcf service.

I didn't add service reference or created a client proxy.

I have a problem. How to access DataContract class and set datamember values..?

I have a wsdl file. I can't use proxy class or add service reference .

I have seen many samples passing xml string(created manually) in request stream.

How can I access datacontract classes using this htpwebrequest..?

any suggestion is appreciated.
Posted
Comments
   
Not clear. The whole purpose of Data Contract is to serialize and deserialize some arbitrary object graph.
There is no such thing as "how to access a class". You receive a reference to the object representing an object graph.
—SA
[no name] 18-Nov-13 7:47am
   
I mean how can I set values to datacontract object...!
How can I discover that, the service expose datacontract class using the httpwebrequest and not service reference. by service reference, one can know the datacontract class members.
Sergey Alexandrovich Kryukov 18-Nov-13 12:55pm
   
Please see my answer.
—SA

1 solution

From stream on in your code? The object comes deserialized with the use of DataContractSerializer, please see. It is controlled by [DataMember] attributes and does not require anything, not even access modifiers. Please see:
http://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer(v=vs.110).aspx[^].

If you need to access something from your semantic code, you need to make a property (properties) for that, or add internal or public access modifier to existing property (properties). Internal for access from the same assembly, public for access from other (referencing) assemblies. Please see:
http://msdn.microsoft.com/en-us/library/ms173121.aspx[^],
Conversion failed when converting date and/or time from character string.?[^],
http://msdn.microsoft.com/en-us/library/aa288470%28v=vs.71%29.aspx[^],
http://msdn.microsoft.com/en-us/library/vstudio/x9fsa0sw%28v=vs.110%29.aspx[^].

—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900