简体   繁体   中英

Response objects from WCF Service

I have a WCF service that looks something like this

 [OperationContract]
 [WebGet(ResponseFormat = WebMessageFormat.Xml)]
 CompositeType GetCompositeTypeForUser(int userid);

...with a CompositeType object that looks something like this:

    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public List<string> stuffAroundMe = new List<string>();

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }

Whenever I call my service I get back a blob of XML data that describes the particular CompositeType. Is there a way to get a CompositeType object back on the client side without having to parse a bunch of XML and manually create a new CompositeType object?

Additionally I have code that lives both in C# on Visual Studio as well as Java on an Android app (the code that is actually calling the web service). Is there a way to avoid parsing lots of xml when I can control the objects being passed from both sides?

Use a web service client library instead of calling the service manually. For .NET the svcutil tool would be used to create the required client code. It looks like something similar is available for java: What tools exist in Java that are equivalent to svcutil.exe for .NET?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM