1

我创建了一个 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 并获取(或设置)数据?

应用程序配置:

<?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>
4

2 回答 2

1

问题已经解决了。我只需要在定义我的客户端变量后添加此代码:

System.ServiceModel.Security.UserNamePasswordClientCredential cre = client.ClientCredentials.UserName;

cre.UserName = " "; cre.Password = " ";

于 2020-07-14T08:24:53.357 回答
0

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

于 2022-01-20T11:33:08.410 回答