如何通过代码动态添加NAV odata webservice

时间:2017-01-12 11:32:26

标签: c# odata dynamics-nav

我使用visual studio中的Add Service Reference选项添加了odata webservice参考。但是客户建议我们通过在web.config中使用url来编写代码。

将来如果他们必须切换到不同的网址,那么他们就很容易添加它。

1 个答案:

答案 0 :(得分:0)

这很容易做到。

您只需保留服务参考,因为它包含服务合同。您可以将URL存储在配置文件中。

<appSettings>
   <add key="ServiceURL" value="http://somewhere.com/Service" />
</appSettings>

在调用服务之前,请通过

修改其URL
reference.Endpoint.Address = ConfigurationManager.AppSettings["ServiceURL"];