Sdílet prostřednictvím


Defining the summary

Web Services for Microsoft Dynamics GP uses a summary document when a GetList method retrieves a list of documents. To add a class that defines the data members of your summary document, complete the following steps:

  1. Create a summary class.

    From the Project menu, choose Add Class. Select Class from the List of Templates in the Add New Item window. Enter a name for your class and click Add. Visual Studio adds a class to your namespace and a file to your project.

    Your summary document class should follow the standard naming convention. Typically, the summary document name begins with document type name followed by "Summary".

DocumentType Summary
The following example shows the name of the summary document class for Leads:

<pre class="checklistscript" IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml">LeadSummary
To create a summary document class for leads, you would enter LeadSummary.cs in the Name box. The following sample code shows the LeadSummary class:

<pre class="checklistscript" IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml">class LeadSummary

{

}

  1. Verify the namespace reference.

    If your class file does not already include it, add a using statement for the following namespace:

    • Microsoft.Dynamics.Common

  2. Mark the class as serializable.

    Add the Serializable and DataContract attributes.

    [Serializable, DataContract]
    

public class LeadSummary {

}

  1. Inherit from the BusinessObject class.

    The summary class inherist from Microsoft.Dynamics.Common.BusinessObject class.

    The following sample code shows how the LeadSummary class inherits from the BusinessObject class:

    public class LeadSummary : BusinessObject
    

{

}

  1. Add the data members.

    Add a private data member for each data field you want to include in the summary document. Add each data member to the summary document class that you created. The following sample code defines the data members of a lead summary:

    private LeadKey key;
    

private string name; private string salespersonID; private bool qualifiedLead; private string leadSource; private DateTime modifiedDate;

  1. Add a property for each data member.

    Add a property that provides access to each data member. The property allows you to set or retrieve the value of each data member. Add the properties to the summary document class immediately after the data members.

    Use the DataMember attribute to identify each property as a data member. In addition, set the EmitDefaultValue property to false for all reference types and non-nullable enumeration types.

    The following sample code shows the properties of the LeadSummary class:

    [DataMember(EmitDefaultValue = false)]
    

public LeadKey Key { get{return key;} set{key = value;} } [DataMember(EmitDefaultValue = false)] public string Name { get{return name;} set{name = value;} } [DataMember(EmitDefaultValue = false)] public string SalespersonID { get{return salespersonID;} set{salespersonID = value;} } [DataMember] public bool QualifiedLead { get{return qualifiedLead;} set{qualifiedLead = value;} } [DataMember(EmitDefaultValue = false)] public string LeadSource { get{return leadSource;} set{leadSource = value;} } [DataMember] public DateTime ModifiedDate { get{return modifiedDate;} set{modifiedDate = value;} }

  1. Add a private method to initialize data fields.

    Add a method to specify the initial value of the Key data field. Typically, the initialize method provides default values for data fields that cannot be null. The constructor and OnDeserializing methods use this method.

    The following sample code initializes the Key property of the LeadSummary class. Notice how an empty LeadKey is used to initialize the Key property.

    public LeadSummary()
    

{ Key = new LeadKey(); Key.Id = ""; }

  1. Add a constructor and OnDeserializing method.

    Create a class constructor and OnDeserializing method. The OnDeserializing method enables your class to be serialized by the Dynamics GP Service framework. Call the Initialize method from both of these methods.

    The following sample code shows the constructor and OnDeserializing method for the LeadKey class. Notice how the OnDeserializing attribute is added to the OnDeserializing method.

    public LeadSummary()
    

{ Initialize(); }

[OnDeserializing] public new void OnDeserializing(StreamingContext context) { Initialize(); }

  1. Add a GetInstance method.

    Add a static GetInstance method that returns an instance of your summary object.

    The following sample code shows the GetInstance method of the LeadSummary class.

    public static LeadSummary GetInstance()
    

{ return new LeadSummary(); }

  1. Save the class.

    From the File menu, choose Save.