Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - OperationContract formatting problem

 
 
Old 03-04-2006   #1 (permalink)
Amit Sharan


 
 

OperationContract formatting problem

HI,

I'm working with winfx Beta2 and having a problem controlling the way
OperationContract methods are serialized/deserialized.

I need a pretty high granularity controll similar to the one given in asmx
web methods using [SoapDocumentMethodAttribute] [XmlElement] and friends.
(e.g. attributed controll over the method paramters elements names, name of
return value, name of result element, etc).
--------------------------------------------------------------------------------
example:

[ServiceContract]
interface MyService
{
[OperationContract]
MyObject DoSomething ( MyObject obj );
}

Indigo Default Request Serialization:

<s:Envelope>...
<s:Body>
<DoSomething>
<obj>....object serialization..<obj>
</DoSomething>
</s:Body>
</s:Envelope>

Desireable Request Serialization:

<s:Envelope>...
<s:Body>
<DoSomething>
<MyObject>....object serialization..<MyObject>
</DoSomething>
</s:Body>
</s:Envelope>

Indigo Default Response Serialization:

<s:Envelope>...
<s:Body>
<DoSomethingResponse>
<DoSomethingResult>...object serialization..</DoSomethingResult>
</DoSomethingResponse>
</s:Body>
</s:Envelope>

Desirable Response Serialization:

<s:Envelope>...
<s:Body>
<DoSomethingResult>
<MyObject>...object serialization..</MyObject>
</DoSomethingResult>
</s:Body>
</s:Envelope>

Any suggestions?

Thanks.



My System SpecsSystem Spec
Old 03-04-2006   #2 (permalink)
Roman Kiss [MVP]


 
 

Re: OperationContract formatting problem

Use the XmlSerializerFormatAttribute to decorate your OperationContract

[ServiceContract]
interface MyService
{
[OperationContract]
[XmlSerializerFormat]
MyObjectResponse DoSomething ( MyObjectRequest obj );
}

and IXmlSerializable interface for your custom serialization/deserialization
Request/Response object, see the following code snippet:

public class MyObjectRequest : IXmlSerializable
{
// fields
private MyObject _myObject;

// properties
public MyObject MyObject { get; set;}

// constructors
public MyObjectRequest() {}

// IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
// create schema
return null;
}
public void ReadXml(XmlReader reader)
{
reader.ReadStartElement("DoSomething", "MyNamespace");
while (reader.NodeType != XmlNodeType.EndElement)
{
MyObject = reader.ReadElementContentAsObject("MyObject",
"MyNamespace") as MyObject;
// more objects
reader.MoveToContent();
}
}
public void WriteXml(XmlWriter writer)
{
writer.WriteStartElement("DoSomething", "MyNamespace");
if (MyObject != null)
{
XmlSerializer xs = new XmlSerializer(MyObject.GetType());
xs.Serialize(writer, MyObject);
}
// more objects
writer.WriteEndElement();
}
}




Roman



"Amit Sharan" <amit.sharan@clicksoftware.com> wrote in message
news:B2AAC4F2-788B-4E67-A64C-4B17EAE2D13D@microsoft.com...
> HI,
>
> I'm working with winfx Beta2 and having a problem controlling the way
> OperationContract methods are serialized/deserialized.
>
> I need a pretty high granularity controll similar to the one given in asmx
> web methods using [SoapDocumentMethodAttribute] [XmlElement] and friends.
> (e.g. attributed controll over the method paramters elements names, name
> of
> return value, name of result element, etc).
> --------------------------------------------------------------------------------
> example:
>
> [ServiceContract]
> interface MyService
> {
> [OperationContract]
> MyObject DoSomething ( MyObject obj );
> }
>
> Indigo Default Request Serialization:
>
> <s:Envelope>...
> <s:Body>
> <DoSomething>
> <obj>....object serialization..<obj>
> </DoSomething>
> </s:Body>
> </s:Envelope>
>
> Desireable Request Serialization:
>
> <s:Envelope>...
> <s:Body>
> <DoSomething>
> <MyObject>....object serialization..<MyObject>
> </DoSomething>
> </s:Body>
> </s:Envelope>
>
> Indigo Default Response Serialization:
>
> <s:Envelope>...
> <s:Body>
> <DoSomethingResponse>
> <DoSomethingResult>...object serialization..</DoSomethingResult>
> </DoSomethingResponse>
> </s:Body>
> </s:Envelope>
>
> Desirable Response Serialization:
>
> <s:Envelope>...
> <s:Body>
> <DoSomethingResult>
> <MyObject>...object serialization..</MyObject>
> </DoSomethingResult>
> </s:Body>
> </s:Envelope>
>
> Any suggestions?
>
> Thanks.
>
>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
problem with lastwritetime and formatting. PowerShell
Problem formatting a dvd Vista music pictures video
Problem formatting date PowerShell
Formatting U3 device problem Vista hardware & devices
Formatting Problem Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46