连接到 NetSuite Web 服务时出现 SOAP 错误:“命名空间前缀 'soapenv' 未定义”

Cha*_*arl 5 c# soap netsuite suitetalk

通过 Suitetalk API 连接到 NetSuite 生产帐户时,我收到以下错误:

在此输入图像描述

我在连接到该客户端的沙盒帐户时没有遇到问题。我正在通过 C# WCF 项目进行连接。我不认为问题出在 c# 项目上,因为此代码正在与许多其他客户端一起在生产中使用。

在我看来,返回的 SOAP 消息格式不正确 - SOAP 消息中的“soapenv”元素之前似乎有一个换行符。在针对 API 创建“get”请求(使用护照登录)时,我收到此错误。不过,任何 API 调用都会出现此错误,我也尝试过通过 API 简单登录。

我已经仔细检查了该客户的登录详细信息和帐户信息,一切似乎都井井有条。此外,如果此信息不正确,我应该收到身份验证错误 - 而不是格式错误的 SOAP 消息。

任何帮助将不胜感激,谢谢!

Cha*_*arl 3

事实证明,我需要使用 webservices.na3.netsuite WSDL。我的印象是常规的“webservices.netsuite”WSDL 会将任何请求定向到正确的服务器。

因此,当通过 SuiteTalk 连接到 NetSuite 帐户时,请务必使用正确的 WSDL 并指定正确的端点以及您的登录凭据。登录 NetSuite 帐户后,您可以通过查看 URL 来检查您的帐户托管在哪个服务器上。

更新

我利用最新的“DataCenterAwareNetSuiteService”类来动态获取我尝试连接的当前帐户的正确数据中心:

class DataCenterAwareNetSuiteService : NetSuiteService
{

    private System.Uri OriginalUri;

    public DataCenterAwareNetSuiteService(string account, bool doNotSetUrl)
        : base()
    {
        OriginalUri = new System.Uri(this.Url);
        if (account == null || account.Length == 0)
            account = "empty";
        if (!doNotSetUrl)
        {
            //var temp = getDataCenterUrls(account);
            DataCenterUrls urls = getDataCenterUrls(account).dataCenterUrls;
            Uri dataCenterUri = new Uri(urls.webservicesDomain + OriginalUri.PathAndQuery);
            this.Url = dataCenterUri.ToString();
        }
    }

    public void SetAccount(string account)
    {
        if (account == null || account.Length == 0)
            account = "empty";

        this.Url = OriginalUri.AbsoluteUri;
        DataCenterUrls urls = getDataCenterUrls(account).dataCenterUrls;
        Uri dataCenterUri = new Uri(urls.webservicesDomain + OriginalUri.PathAndQuery);
        this.Url = dataCenterUri.ToString();
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的调用方式如下:

new DataCenterAwareNetSuiteService("*account number*", false);
Run Code Online (Sandbox Code Playgroud)