创建WCF服务时要避免哪些DataContract对象类型?

时间:2012-02-24 13:47:24

标签: c# .net wcf datacontract

我想知道在创建types时我应该避免的所有WCF DataContract

我希望我的Service与任何Client平台完全兼容。

这是我的interface

public interface IShopriteService
{
    [OperationContract]
    ChangePasswordResponse ChangePassword(ChangePasswordRequest changePasswordRequest);

    [OperationContract]
    GetCampaignSchedulePlacementsResponse GetCampaignSchedulePlacements(GetCampaignSchedulePlacementsRequest getCampaignSchedulePlacementsRequest);

    [OperationContract]
    ConfirmDownloadResponce ConfirmDownload(ConfirmDownloadRequest confirmDownloadRequest);

    [OperationContract]
    UploadCampaignSchedulePlacementsResponse UploadCampaignSchedulePlacements(UploadCampaignSchedulePlacementsRequest uploadCampaignSchedulePlacementsRequest);
}

[DataContract]
public class ChangePasswordRequest
{
    [DataMember]
    public Guid ServiceProviderGuid
    {
        get;
        set;
    }

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

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

[DataContract]
public class ChangePasswordResponse
{
    [DataMember]
    public string Message
    {
        get;
        set;
    }
}

[DataContract]
public class GetCampaignSchedulePlacementsRequest
{
    [DataMember]
    public Guid ServiceProviderGuid
    {
        get;
        set;
    }

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

[DataContract]
public class GetCampaignSchedulePlacementsResponse
{

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

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

    [DataMember]
    public List<CampaignSchedulePlacement> CampaignSchedulePlacementList
    {
        get;
        set;
    }
}

[DataContract]
public class ConfirmDownloadRequest
{
    [DataMember]
    public Guid ServiceProviderGuid
    {
        get;
        set;
    }

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

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

[DataContract]
public class ConfirmDownloadResponce
{
    [DataMember]
    public string Message
    {
        get;
        set;
    }
}

[DataContract]
public class UploadCampaignSchedulePlacementsRequest
{
    [DataMember]
    public Guid ServiceProviderGuid
    {
        get;
        set;
    }

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

    [DataMember]
    public List<CampaignSchedulePlacement> CampaignSchedulePlacementList
    {
        get;
        set;
    }
}

[DataContract]
public class UploadCampaignSchedulePlacementsResponse
{

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

[DataContract]
public class CampaignSchedulePlacement
{
    [DataMember]
    public Guid CampaignSchedulePlacementUID
    {
        get;
        set;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    [DataMember]
    public short Columns
    {
        get;
        set;
    }

    [DataMember]
    public int Quantity
    {
        get;
        set;
    }

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

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

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

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

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

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

    [DataMember]
    public decimal GrossUnitRateAmount
    {
        get;
        set;
    }

    [DataMember]
    public decimal GrossRateAmount
    {
        get;
        set;
    }

    [DataMember]
    public decimal DiscountAmount
    {
        get;
        set;
    }

    [DataMember]
    public decimal CommissionAmount
    {
        get;
        set;
    }

    [DataMember]
    public decimal NettCostAmount
    {
        get;
        set;
    }

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

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

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

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

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

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

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

    [DataMember]
    public bool IsCancelledInChase
    {
        get;
        set;
    }

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

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

    [DataMember]
    public decimal ClientInvoiceAmount
    {
        get;
        set;
    }

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

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

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

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

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

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

我的服务是否与所有平台兼容?

2 个答案:

答案 0 :(得分:4)

类型应使用SerializableAttribute,DataContractAttribute标记,或者是XML Serializable。只要一个类型支持,你会没事的。如果不能,WCF会通知您。你的合同看起来很好,因为它只使用了所有覆盖的原始类型,以及所有DataContracts的复杂类型。

Here's a detailed article on supported types

答案 1 :(得分:1)

您可能需要考虑使您的WCF服务RESTful。我认为这将使非WCF更容易使用该服务。这:http://www.amazon.com/RESTful-NET-ebook/dp/B0028N4W74/ref=sr_1_3?ie=UTF8&qid=1330091833&sr=8-3可能是一个很好的阅读。