简体   繁体   English

在AX 2012中,如何将WCF服务公开为REST

[英]In AX 2012, How to expose WCF service as REST

Right now i am exposing services from AX 2012, how to configure it to expose it as REST? 现在我要公开AX 2012中的服务,如何配置它以将其公开为REST?

I have to use this service in MAC Xcode for IOS integration, I believe its easy if it is a REST than SOAP. 我必须在MAC Xcode中使用此服务来进行IOS集成,如果它是REST而不是SOAP,我相信它很容易。

Well, there is an interesting question but with no straightforward answer :( 好吧,有一个有趣的问题,但没有简单的答案:(

I would say there is no easy and simple way of exposing your Ax WCF service as REST, but there are workarounds. 我想说没有简单简便的方法将Ax WCF服务公开为REST,但是有解决方法。 Here is what I would do. 这就是我要做的。

You can create your own ASP.NET WebAPI project which can be hosted on an IIS or self hosted in service or executable is also possible. 您可以创建自己的ASP.NET WebAPI项目,该项目可以托管在IIS上,也可以自行托管在服务或可执行文件中。 ( WebAPI website and tutorial to create a simple WebAPI project). WebAPI网站教程可创建一个简单的WebAPI项目)。 This WebAPI project is actually using ASP.NET MVC 4.0 so you can create controllers to contain the logic to fetch data. 此WebAPI项目实际上使用的是ASP.NET MVC 4.0,因此您可以创建控制器以包含用于提取数据的逻辑。

In the tutorial they are loading products and in the controller an array is used for demo purposes. 在本教程中,他们正在加载产品,并且在控制器中,阵列用于演示目的。

Product[] products = new Product[] 
    { 
        new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, 
        new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, 
        new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } 
    };

Well, now what you can do is replace this by a service call to your Ax WCF service. 好了,现在您可以做的是将其替换为对Ax WCF服务的服务调用。 By doing this, outside users can actually do HTTP requests to your WebAPI site and WebAPI will handle all of the routing for you and will return the JSON format. 这样,外部用户实际上可以向您的WebAPI站点发出HTTP请求,并且WebAPI将为您处理所有路由并返回JSON格式。

For example: 例如:

  • "http://localhost:xxxx/api/products/1" “ http:// localhost:xxxx / api / products / 1”
  • "http://localhost:xxxx/api/products?category=hardware" “ http:// localhost:xxxx / api / products?category =硬件”

And in the background, the controller itself can do service calls to Ax using the SOAP way with WCF. 并且在后台,控制器本身可以使用WCF使用SOAP方式对Ax进行服务调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM