0

I have created WCF REST API. I have implemented following service interface and service method for the API.

service interface:

[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
ObjAPI GetAPIRequest(ObjAPI objAPI)

service :

public ObjAPI GetAPIRequest(ObjAPI objAPI)
{
   return new ExternalAPI().GetAPIRequest(objAPI);
                
}

code of ObjAPI class

    [System.Runtime.Serialization.DataContract(Namespace = "")]
    public class ObjAPI
    {
        [System.Runtime.Serialization.DataMember]        
        public int ID { get; set; }   

        [System.Runtime.Serialization.DataMember]
        public Client Client { get; set; }       


    }
}

My ObjAPI contain another object Client, then I have passed Following XML to the service.

<ObjAPI> 
<ID> 1 </ID>
<Client> 
< ClientNumber>0067HA000001</ ClientNumber>
</Client > 
</ ObjAPI >

But in the GetAPIRequest method, ID field is getting its value and client object become null.

How can I fix this Issue?

4
  • Can you please share ObjAPI class? Commented Jul 4, 2014 at 9:07
  • [System.Runtime.Serialization.DataContract(Namespace = "")] public class ObjAPI { [System.Runtime.Serialization.DataMember] public int ID { get; set; } [System.Runtime.Serialization.DataMember] public Client Client { get; set; } } } Commented Jul 4, 2014 at 9:14
  • 1
    @Prasad - 1. Edit your question and add your code there, please. 2. Post the code for GetAPIRequest, as the issue may be there. Commented Jul 4, 2014 at 9:18
  • @Tim : actually at the service class object value getting null vale. Commented Jul 4, 2014 at 9:23

1 Answer 1

1
[ServiceContract]
public interface IInterface
{
    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
    ObjAPI GetAPIRequest(ObjAPI objAPI)
}

public class Service: IInterface
{
    public ObjAPI GetAPIRequest(ObjAPI objAPI)
    {
       return new ExternalAPI().GetAPIRequest(objAPI);
    }
}

[System.Runtime.Serialization.DataContract(Namespace = "")]
public class ObjAPI
{
    [System.Runtime.Serialization.DataMember]        
    public int ID { get; set; }   

    [System.Runtime.Serialization.DataMember]
    public Client Client { get; set; }       
}

We also must set DataContract and DataMember attributes for Client class

[System.Runtime.Serialization.DataContract(Namespace = "")]
public class Client
{
    [System.Runtime.Serialization.DataMember]        
    public string ClientNumber { get; set; }     
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.