简体   繁体   English

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

[英]SOAP error when connecting to NetSuite web services: “Namespace prefix ' soapenv' not defined”

I am getting the following error when connecting to a NetSuite production account, through the Suitetalk API: 通过Suitetalk API连接到NetSuite生产帐户时出现以下错误:

在此输入图像描述

I don't have problems connecting to the Sandbox account for this client. 连接到此客户端的Sandbox帐户时没有问题。 I am connecting through a C# WCF project. 我正在通过C#WCF项目进行连接。 I don't believe the problem is with the c# project, since this code is being used in Production with many other clients. 我不相信问题出在c#项目中,因为此代码在生产中与许多其他客户端一起使用。

It seems to me like the SOAP message being returned is incorrectly formatted - there seems to be a line break before the 'soapenv' element in the SOAP message. 在我看来,返回的SOAP消息格式不正确 - 似乎在SOAP消息中的'soapenv'元素之前有一个换行符。 I am getting this error when creating a "get" request against the API(using passport login). 我在针对API创建“获取”请求时使用护照登录时收到此错误。 This error occurs on any API call though, I did try simply logging in through the API as well. 但是,任何API调用都会发生此错误,我也尝试过通过API登录。

I have double checked the login details and account information for this client and everything seems in orders. 我已经仔细检查了这个客户端的登录详细信息和帐户信息,所有内容都在订单中。 Besides, if this information is incorrect, I should be getting authentication errors - not malformed SOAP messages. 此外,如果此信息不正确,我应该收到身份验证错误 - 而不是格式错误的SOAP消息。

Any help will be appreciated, thanks! 任何帮助将不胜感激,谢谢!

It turns out that I needed to use the webservices.na3.netsuite WSDL. 事实证明我需要使用webservices.na3.netsuite WSDL。 I was under the impression that the regular "webservices.netsuite" WSDL would direct any requests to the correct server. 我的印象是,常规的“webservices.netsuite”WSDL会将任何请求定向到正确的服务器。

So when connecting to a NetSuite account through SuiteTalk, be sure to make use of the correct WSDL and specify the correct endpoint along with your login credentials. 因此,当通过SuiteTalk连接到NetSuite帐户时,请确保使用正确的WSDL并指定正确的端点以及您的登录凭据。 You can check which server your account is hosted on by looking at the URL when logged into your NetSuite account. 通过在登录NetSuite帐户时查看URL,您可以检查您的帐户所在的服务器。

Update 更新

I made use of the newest 'DataCenterAwareNetSuiteService' class to dynamically get the correct data center for the current account that I am trying to connect to: 我利用最新的“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();
    }
}

The above is called like so: 以上称为如下:

new DataCenterAwareNetSuiteService("*account number*", false);

With the latest version of NetSuite, some changes have been made to URLs. 使用最新版本的NetSuite,对URL进行了一些更改。 For instance, now you can have more than one SandBox URL. 例如,现在您可以拥有多个SandBox URL。 Because of this, the URL format has changed. 因此,URL格式已更改。 The account number used when authenticating is also now different. 验证时使用的帐号现在也不同。 For sandboxes the account Id is now passed up as ACCOUNTNUMBER_SANDBOXID, for example 12345678_SB1. 对于沙箱,帐户ID现在作为ACCOUNTNUMBER_SANDBOXID传递,例如12345678_SB1。

You can determine the URLs for the SOAP and REST services by using the datacenterurls endpoint and supplying the account # you would like to determine the URLS for. 您可以使用datacenterurls端点并提供您想要确定URLS的帐户来确定SOAP和REST服务的URL。

https://rest.netsuite.com/rest/datacenterurls?account=YOUR_ACCOUNT_NUMBER https://rest.netsuite.com/rest/datacenterurls?account=YOUR_ACCOUNT_NUMBER

The functionality below is based on the answer from @Charl above. 以下功能基于上面@Charl的答案。 I have made a couple changes below that provides the same functionality without using inheritance. 我在下面进行了一些更改,提供相同的功能而不使用继承。 This may be a simpler implementation for a newer programmer who does not know how to use an inherited class. 对于不知道如何使用继承类的新程序员来说,这可能是一个更简单的实现。

    var accountId = "1234567"; // Insert your account ID here
    var Service = new NetSuiteService();
    Service.Url = new Uri(Service.getDataCenterUrls(accountId).dataCenterUrls.webservicesDomain + new Uri(Service.Url).PathAndQuery).ToString();

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

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