6.5 Tīmekļa pakalpes servera c# koda organizācija

Ja iepriekšējā solī c# kods ir noģenerēts vienā failā, tad tajā ir noģenerēts arī Interface kods (metožu kontrakts). Saskaņā ar labo praksi vajag iznest šo daļu atsevišķā failā IXXX.cs.

Piemērs no Submission.cs:

using System.ServiceModel;
namespace Viss.BLService.Submission
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace = "http://ivis.eps.gov.lv/BLS/Submission/v1-0", ConfigurationName = "ISubmission", Name = "ISubmission")]
    [ServiceKnownType(typeof(GetSubmissionListResponseStructure))]
    public interface ISubmission
    {                              
        // CODEGEN: Generating message contract since the wrapper namespace (http://ivis.eps.gov.lv/XMLSchemas/100001/Ekons2/v1-0) of message SaveDraftSubmissionRequest does not match the default value (http://ivis.eps.gov.lv/BLS/Submission/v1-0)
        [System.ServiceModel.OperationContractAttribute(Action = "http://ivis.eps.gov.lv/BLS/Submission/v1-0:saveDraftSubmissionIn", ReplyAction = "*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(NotificationBase))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(PagedListBaseStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(GetPagedListBaseStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AuthorityIdStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SubmissionDetailsBaseStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(UploadFilesRequestStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AddresseeChoiceBaseStructure))]
        SaveDraftSubmissionResponse SaveDraftSubmission(SaveDraftSubmissionRequest request);
 
        // CODEGEN: Generating message contract since the wrapper namespace (http://ivis.eps.gov.lv/XMLSchemas/100001/Ekons2/v1-0) of message DeleteDraftSubmissionRequest does not match the default value (http://ivis.eps.gov.lv/BLS/Submission/v1-0)
        [System.ServiceModel.OperationContractAttribute(Action = "http://ivis.eps.gov.lv/BLS/Submission/v1-0:deleteDraftSubmissionIn", ReplyAction = "*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(NotificationBase))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(PagedListBaseStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(GetPagedListBaseStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AuthorityIdStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SubmissionDetailsBaseStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(UploadFilesRequestStructure))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AddresseeChoiceBaseStructure))]
        DeleteDraftSubmissionResponse DeleteDraftSubmission(DeleteDraftSubmissionRequest request);
...
}

Noģenerētajā .cs fala beigu daļā ir ģenerēti kontrakta metožu "implementācijas", izsaucot atbilstošas XXXImplementation metodes. Piemēram, Submission.cs failā ir šādi izsaukumi:

    public partial class Submission : ISubmission
    {
        public virtual SaveDraftSubmissionResponse SaveDraftSubmission(SaveDraftSubmissionRequest request)
        {
            return SaveDraftSubmissionImplementation(request);
        }
        public virtual DeleteDraftSubmissionResponse DeleteDraftSubmission(DeleteDraftSubmissionRequest request)
        {
            return DeleteDraftSubmissionImplementation(request);
        }
        public virtual AddAttachmentsResponse AddAttachments(AddAttachmentsRequest request)
        {
            return AddAttachmentsImplementation(request);
        }
        ...

Īsto implementāciju vajag izdarīt atsevišķā cs failā, lietojot "partial" specifikāciju (.svc.cs). Piemēram, Submission.svc.cs

using System.ServiceModel;
...
namespace Viss.BLService.Submission
{
    public partial class Submission : ISubmission
    {
        // SEARCH
        public GetSubmissionListResponse GetSubmissionListImplementation(GetSubmissionListRequest request)
        {
            string userId = null;// "PK:07018910814";
            GetSubmissionListResponseStructure responseStructure = new GetSubmissionListResponseStructure();
            GetSubmissionListRequestStructure requestStructure = request.GetSubmissionListRequest1;
            //atgriez kautko, lai nav null
            responseStructure.SubmissionListDetails = new SubmissionListDetailsStructure() { };
            responseStructure.SubmissionListDetails.Offset = request.GetSubmissionListRequest1.Offset;
            responseStructure.SubmissionListDetails.Records = request.GetSubmissionListRequest1.Records;
            responseStructure.SubmissionListDetails.SubmissionSummaryList = new SubmissionSummaryListStructure();
            responseStructure.SubmissionListDetails.SubmissionSummaryList.SubmissionSummaryListRow = new List<SubmissionSummaryListRowStructure>();
            ...