top of page
  • Hina Garg

Data Exchange B/w Sitecore XC and XP by using Service Proxy - Part 2

Updated: Oct 5, 2020

Hey Everyone,


In my previous blog post, I described about generating an end point in the commerce engine which could be found here : Part-1 In this post, I am going to explain the setup of Service Proxy.


Service Proxy is a strongly typed OData client project provided by Sitecore as part of the Sitecore.Commerce.Engine.SDK package. This project enables our storefront to reference the plugins created in the commerce engine. It consists of two OData connected services, the CommerceOps service and the CommerceShops service. Each connected service connects to a metadata endpoint on the Commerce Engine. The endpoint is defined in the ConnectedService.json file present inside the connected service.


Steps to do the set up:

  1. The first step is to grab the Sitecore.Commerce.ServiceProxy project from the Sitecore.Commerce.Engine.SDK Package. It will look like below:

2. Next step is to decide the placement of this project. If you are following the Helix architecture for your project you could keep it in the Foundation layer of your website solution.


3. Third step is to generate the proxy. Generating proxy helps us to create copies of the entities and controllers in a format that our storefront projects can reference in a strongly typed way.


Sitecore Commerce 9.3 supports 0.3.0 ODataConnectedServices when the latest released version of ODataConnectedServices is 0.10.0.


Important things to note before we generate the proxy:

  1. Check the version of the ODataConnectedServices supported by Sitecore Commerce For example: If you are using Sitecore Commerce 9.3 you will have to use OData Connected Service 0.3.0. If you try to use a version higher than 0.3.0 you will come across several errors.

  2. Use Visual Studio 2017 along with ODataConnectedServices 0.3.0 to generate the proxy. If you want to use Visual Studio 2019 there might be some work required for using it as OData version of 0.4.0 adds support for VS 2019.

For me, Visual Studio 2017 and ODataConnectedServices 0.3.0 are generating correct proxy without errors for Sitecore Commerce 9.3. Before figuring out the correct versions I ran into lots of errors of several kinds.

Generate the proxy:

  1. Uninstall the current version of the OData Connected Service from Visual Studio.

  2. Download and install the older version of the OData Connected Service.

  3. Update the connected services. (Connected Services>Commerce Ops/Commerce Shops>Update ODataConnectedService...). A window like the one shown below will open. The service name and address could be updated in ConnectedService.json file.If you have deployed the engine and running on default port 5000, make sure that you run it before clicking on next button.


d. Click on the next button and leave the default options as checked as shown below:

e. Finish and Save.


4. After generating the proxy next step is to reference this project under the project you would like to use it for making calls to the service defined in the engine.


5. Build the solution.


---------------------------------------------------------------------------------


Possible Error on Invoking the Command via Proxy:


Error: Versions incompatibility for Microsoft.OData.Core between Sitecore XC and Sitecore XP. Sitecore.XA.Foundation.Common requires Microsoft.OData.Core 7.5 but the project Service Proxy project has Microsoft.OData.Core 6.19 added to it so you might get an error: Method not found: 'Microsoft.OData.Client.DataServiceActionQuerySingle`1<Sitecore.Commerce.Core.Commands.CommerceCommand>


Solution to fix above error:

Add references to following dll's: Microsoft.OData.Client, Microsoft.OData.Core, Microsoft.OData.Edm, Microsoft.Spatial version 6.19.0 in your project and set build to false so that these dll's don't get deployed to the root.





137 views0 comments

Commenti


bottom of page