public void DoWork(IRequest request) { //// check for resource kind existence and supported types //if (_requestContext.ResourceKind == SupportedResourceKinds.None) // throw new RequestException("Invalid request: The service {0} is a resource based service."); // if request was done in the context of a resource kind -> check for supported resourceKinds if (_requestContext.ResourceKind != SupportedResourceKinds.None) { if (!(_requestContext.ResourceKind == SupportedResourceKinds.salesOrders || _requestContext.ResourceKind == SupportedResourceKinds.salesOrderLines)) { throw new RequestException("Invalid request: The service {0} is only supported by salesOrders and salesOrderLines."); } } // read entry from stream SyncFeedEntry entry = new SyncFeedEntry(); XmlReader reader = XmlReader.Create(request.Stream); reader.MoveToContent(); entry.ReadXml(reader, typeof(ComputePriceRequestPayload)); // underlying resources for price computing computePriceRequesttype computePriceRequest; CommodityIdentity[] productIds; // will contain local ids of the commodity referenced by line items. // Could contain empty items if commodity id could not be found. // compute price computePriceResponsetype computePriceResponse; if (null == entry.Payload) { throw new RequestException("Invalid Xml input stream. Could not parse the payload."); } computePriceRequest = ((ComputePriceRequestPayload)entry.Payload).ComputePriceRequest; #region Trading Account (discounted) // get the undelying trading account // is null if request is not in the context of an account. // if no account found means that the account exists in CRM only // and has not yet been linked with ERP. ERP could treat the account as a // prospect account and generate a price for the account, or if this is not // possible it could return an error. #endregion #region PricingDocument (only salesOrder suppported) // document associated with this pricing request (e.g. the Sales Order, Quotation, Purchase Order number). // could be of any type of enumeration "pricingDocumenttype" // if no document exists the request is not in the context of a document like order, quote, etc. // TODO: Get the associated document to find out the context of the request. // Validate document type // here: only salesOrder supported // removed to avoid possible errors (OK as this is only an example project) //if (computePriceRequest.pricingDocumentType != pricingDocumenttype.salesOrder) // throw new RequestException("Invalid document type in element 'pricingDocumentType' defined. Only salesOrder supported."); #endregion #region Commodities (for each document lines) // Get Commodity local ids used on the associated document lines. // (the array returned is always of the same size as the number of document lines in the request payload. // If a commodity local id could not be found in feed entry the array item will be null. productIds = this.GetCommodityIds(entry); // (never returns null, but could return an empty array) #endregion // compute price PricingServices pricingServices = new PricingServices(_requestContext.Config); if (_requestContext.ResourceKind == SupportedResourceKinds.salesOrders || _requestContext.ResourceKind == SupportedResourceKinds.None) { computePriceResponse = pricingServices.ComputePrice(computePriceRequest, productIds, false); } else { computePriceResponse = pricingServices.ComputePrice(computePriceRequest, productIds, true); } // create response feed this.BuildResponseFeed(ref request, computePriceResponse); //this.BuildResponseFeed(ref request, cpr); }