Exposing a service to external systems - How should I design the contract?

Posted by Larsi on Stack Overflow See other posts from Stack Overflow or by Larsi
Published on 2009-09-25T10:54:17Z Indexed on 2010/04/05 21:03 UTC
Read the original article Hit count: 231

Filed under:
|
|

Hi!

I know this question is been asked before here but still I'm not sure what to select.

My service will be called from many 3 party system in the enterprise. I'm almost sure the information the service will collect (MyBigClassWithAllInfo) will change during the products lifetime. Is it still a good idea to expose objects?

This is basically what my two alternatives:

    [ServiceContract]
public interface ICollectStuffService
{
    [OperationContract]
    SetDataResponseMsg SetData(SetDataRequestMsg dataRequestMsg);
}

// Alternative 1: Put all data inside a xml file
[DataContract]
public class SetDataRequestMsg
{
    [DataMember]
    public string Body { get; set; }
    [DataMember]
    public string OtherPropertiesThatMightBeHandy { get; set; } // ??
}
// Alternative 2: Expose the objects
[DataContract]
public class SetDataRequestMsg
{
    [DataMember]
    public Header Header { get; set; }
    [DataMember]
    public MyBigClassWithAllInfo ExposedObject { get; set; }
}

public class SetDataResponseMsg
{
    [DataMember]
    public ServiceError Error { get; set; }
}


The xml file would look like this:

<?xml version="1.0" encoding="utf-8"?> <Message>   <Header>     <InfoAboutTheSender>...</InfoAboutTheSender>   </Header>   <StuffToCollectWithAllTheInfo>   <stuff1>...</stuff1> </StuffToCollectWithAllTheInfo> </Message>


Any thought on how this service should be implemented?

Thanks Larsi

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about messaging