Question

I have a site that give me this xml response on my GET request:

<ServerUnits>
    <State Name="ServerName" Date="2008-04-01" >
    <Users>
       <User login="someUser1" Password="123456">
       <User login="someUser2" Password="qwerty">
    </Users>
</ServerUnits>

I want use WCF Client for work with this service. How to discraibe Message Contract of this response for WCF Clien

Was it helpful?

Solution

It is best to create client proxies for the WCF service. It will create the data contracts for you (as mentioned by @Aliostad) so you don't have to create them manually. To do this right click on your solution and select "Add Service Reference..." from the context-menu and enter the address to your WCF service.

OTHER TIPS

I think that WCF is not useful is your case.

A more simple way would be to write objects that match this xml response and just deserialize xml stream onto objects instances.

What you have posted is not a SOAP message so MessageContract is not appropriate.

I imagine what you posted is the SOAP body content so you need to do something along the line of this:

[DataContract]
public class ServerUnits
{
    [DataMember]
    public ServerState State { get; set; }

    [DataMember]
    public List<User> Users { get; set; }
}

[DataContract]
public class ServerState
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public DateTime Date { get; set; }
}

[DataContract]
public class User
{
    [DataMember]
    public string login { get; set; }

    [DataMember]
    public string password { get; set; }

}

UPDATE

Your message is not SOAP. But you can still use the code above if you use webHttpBinding which sends and receives POX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top