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.
![](https://static.wixstatic.com/media/a27d24_8876f2070cbf44108a7419007b8343b6~mv2.png/v1/fill/w_285,h_402,al_c,q_85,enc_auto/a27d24_8876f2070cbf44108a7419007b8343b6~mv2.png)
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:
The first step is to grab the Sitecore.Commerce.ServiceProxy project from the Sitecore.Commerce.Engine.SDK Package. It will look like below:
![](https://static.wixstatic.com/media/a27d24_58c9eb992c0841c39c421ac047b07d65~mv2.png/v1/fill/w_407,h_395,al_c,q_85,enc_auto/a27d24_58c9eb992c0841c39c421ac047b07d65~mv2.png)
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.
![](https://static.wixstatic.com/media/a4cf75_8fe54b6c1c1c434db6f6981e4f48146c~mv2.png/v1/fill/w_772,h_562,al_c,q_90,enc_auto/a4cf75_8fe54b6c1c1c434db6f6981e4f48146c~mv2.png)
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:
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.
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:
Uninstall the current version of the OData Connected Service from Visual Studio.
Download and install the older version of the OData Connected Service.
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.
![](https://static.wixstatic.com/media/a27d24_fb14fa05d0bd40e9aa15fa2bacdcba84~mv2.png/v1/fill/w_980,h_286,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_fb14fa05d0bd40e9aa15fa2bacdcba84~mv2.png)
d. Click on the next button and leave the default options as checked as shown below:
![](https://static.wixstatic.com/media/a27d24_c145c625b31e47a7a194c246dd8fb4d0~mv2.png/v1/fill/w_980,h_267,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_c145c625b31e47a7a194c246dd8fb4d0~mv2.png)
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.
Commenti