This sample project is posted in reply to the forum post: http://social.msdn.microsoft.com/Forums/en-US/554a7c1c-cea7-4743-ad4f-7845da2e9683/sending-xml-string-to-generated-webservice-proxy-stub.
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=
true
)]
public
object
richPresenceField {
get
{
return
this
.richPresenceFieldField;
}
set
if
((
.ReferenceEquals(
.richPresenceFieldField, value) !=
)) {
.richPresenceFieldField = value;
.RaisePropertyChanged(
"richPresenceField"
);
To illustrate, I created a WCF Service using the Visual Studio template and then modified the default service to return the contract provided in the forum post. The class setPresence contains a property that has the richPresenceField shown above.
[ServiceContract]
interface
IService1
[OperationContract]
string
GetData(
int
value);
setPresence GetPresence(setPresence composite);
I wanted my implementation to be a little interesting so I added a couple of changes. In general, the service just echos what it receives but I wanted to add a class that was included in the original contract and introduce a new contract that I manually added to the service.
setPresence GetPresence(setPresence presence)
(presence ==
null
)
throw
new
ArgumentNullException(
"setPresence"
(presence.presenceInfo.richPresence
is
// if a string is sent then try to parse and return as
// an int to illustrate that the type can change
value;
(
.TryParse(((
) presence.presenceInfo.richPresence),
out
value))
presence.presenceInfo.richPresence = value;
// return out a new setPresence
(value==4)
presence.presenceInfo.richPresence =
setPresence { expiration = 4, presenceType =
"test presence"
};
// return out a new MyClass
(value == 5)
MyOtherClass
AnIntWithAnotherName = 3,
MyStringCollection =
[] {
"avalue"
,
"and another"
presence;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.Runtime.Serialization"
"4.0.0.0"
[System.Runtime.Serialization.DataContractAttribute(Name=
"PresenceInfoType"
, Namespace=
"http://schemas.datacontract.org/2004/07/FunnySerialisation"
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(
typeof
(FunnyClient.funnyservice.setPresence))]
(System.MulticastDelegate))]
(System.Delegate))]
(System.ComponentModel.PropertyChangedEventHandler))]
partial
class
PresenceInfoType :
, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
In my client I created a little helper method that returns an setPresence object that contains the object I am trying to verify:
private
static
setPresence BuildSimplePresence(
content)
setPresence
expirationField = 100,
presenceInfoField =
PresenceInfoType
basicPresenceField =
"basic"
richPresenceField = content
},
presenceTypeField =
"a type of presence"
var presence = client.GetPresence(BuildSimplePresence(
"some simple content that will be encoded <here> and <there>."
));
presence = client.GetPresence(BuildSimplePresence(
"12202"
setPresence { expirationField = 1 } ));
"4"
"5"
"System.Xml"
"4.0.30319.18046"
[System.ComponentModel.DesignerCategoryAttribute(
"code"
[System.Runtime.Serialization.DataContractAttribute(Name =
, Namespace =
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType =
"urn:somecompany:presence:soap"
, TypeName =
"MyClass"
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order = 0, ElementName =
"MyIntValue"
[System.Runtime.Serialization.DataMember()]
AnIntWithAnotherName {
;
; }
[System.Xml.Serialization.XmlElementAttribute(Order = 0)]
[] MyStringCollection {
I also had to inform datacontractserializer to expect these type of objects by inserting the knowntypeattribute:
[System.Xml.Serialization.XmlTypeAttribute(Namespace =
(MyOtherClass))]
, System.ComponentModel.INotifyPropertyChanged
Without updating the proxy, I then manually added a class that has the same contract definition but different class structure:
MyClass
[System.Xml.Serialization.XmlElementAttribute(Order = 0, Namespace =
MyIntValue {
And, I need to let the proxy (Reference.cs) know about this new type:
(MyClass))]
This then allows for the following message to be sent (and echoed):
MyClass { MyIntValue = 4, MyStringCollection =
"test1"
"test2"
}}));
Hope this is helpful.
Balaji M Kundalam edited Revision 5. Comment: Typography - minor edit
Maheshkumar S Tiwari edited Revision 3. Comment: Added Tag
Maheshkumar S Tiwari edited Revision 2. Comment: Title casing
Maheshkumar S Tiwari edited Revision 1. Comment: Added Tag and formatting