Web Services 如何从Business Central获取数据?

eh57zj3b  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(138)

我已经做了一个C#项目,我试图连接到我的Business Central云沙盒。
在Business Central中,我用一个新的代码单元做了一个扩展,它有一个我称为“MHSTest”的函数,它只返回一个文本。
在Visual Studio中,我创建了连接到Business Central中SOAP URL的服务引用。因此,我可以在Visual Studio中看到我的函数名“MHSTest”。
当我在Visual Studio中编写此代码时,我得到一个错误,因为它试图匿名连接:

var client = new MHSTest.CSharpCodeunit_PortClient();
myTextBox.Text = client.MHSTest();

如果我尝试下面的方法,我会得到一个错误消息,说“https”是无效的。它必须是“http”。

string endpoint = "">api.businesscentral.dynamics.com/.../CSharpCodeunit";
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.MaxBufferSize = 999999;
binding.MaxReceivedMessageSize = 999999;

var client = new MHSTest.CSharpCodeunit_PortClient(binding, new EndpointAddress(endpoint));

myTextBox.Text = client.MHSTest();

如何连接到Business Central并获取(或设置)数据?
App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Debitorer_Binding">
<security mode="Transport" />
</binding>
<binding name="Debitorer_Binding1" />
<binding name="CSharpCodeunit_Binding">
<security mode="Transport" />
</binding>
<binding name="CSharpCodeunit_Binding1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="api.businesscentral.dynamics.com/.../2999befa-1255-4304-a79a-67de0e24f090/Sandbox/WS/CRONUS%20Danmark%20A%252FS/Page/Debitorer?tenant=msneua5672t92712555&amp;aid=FIN"
binding="basicHttpBinding" bindingConfiguration="Debitorer_Binding"
contract="BCCustomer.Debitorer_Port" name="Debitorer_Port" />
<endpoint address="api.businesscentral.dynamics.com/.../2999befa-1255-4304-a79a-67de0e24f090/Sandbox/WS/CRONUS%20Danmark%20A%252FS/Codeunit/CSharpCodeunit?tenant=msneua5672t92712555&amp;aid=FIN"
binding="basicHttpBinding" bindingConfiguration="CSharpCodeunit_Binding"
contract="MHSTest.CSharpCodeunit_Port" name="CSharpCodeunit_Port" />
</client>
</system.serviceModel>
</configuration>
kpbpu008

kpbpu0081#

问题解决了。我只需要在定义我的客户端变量后添加以下代码:
系统.服务模型.安全.用户名密码客户端凭证cre =客户端.客户端凭证.用户名;
创建用户名=““;证书密码=““;

knpiaxh1

knpiaxh12#

使用Export-NAVData cmdlet从Business Central数据库导出数据。您可以导出公司特定的数据,也可以选择包括全局数据、应用程序数据和应用程序对象。从Business Central数据库导出数据时,数据将存储在扩展名为的文件中。

相关问题