soapenv:Server.userException -> 来自 eBay 交易的错误 API GetSellingManagerSoldListingsRequest

soapenv:Server.userException -> error from eBay Trading API GetSellingManagerSoldListingsRequest

感谢Vancalar的指点和XML代码(参考:),我做了一个测试程序如下:

procedure TForm1.Button1Click(Sender: TObject);
var
  sSOAP: String;
  sCallName, sSiteID, sVersion: String;
  sResponseBody: TStringStream;
  xDoc: IXMLDocument;
begin
  sCallName := 'GetSellingManagerSoldListingsRequest';
  sSiteID := '15';                       // 15 for Australia
  sVersion := '945';

  sSOAP := '<?xml version="1.0"?>'
        + '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'
        + '  xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
        + '  <SOAP-ENV:Header>'
        + '    <NS1:RequesterCredentials xmlns:NS1="urn:ebay:apis:eBLBaseComponents">'
        + '      <eBayAuthToken xmlns="urn:ebay:apis:eBLBaseComponents">' + sToken + '</eBayAuthToken>'
        + '      <NS1:Credentials>'
        + '        <AppId xmlns="urn:ebay:apis:eBLBaseComponents">' + sAppID + '</AppId>'
        + '        <DevId xmlns="urn:ebay:apis:eBLBaseComponents">' + sDevID + '</DevId>'
        + '        <AuthCert xmlns="urn:ebay:apis:eBLBaseComponents">' + sCertID + '</AuthCert>'
        + '      </NS1:Credentials>'
        + '    </NS1:RequesterCredentials>'
        + '  </SOAP-ENV:Header>'
        + '  <SOAP-ENV:Body>'
        + '    <GetSellingManagerSoldListingsRequest xmlns="urn:ebay:apis:eBLBaseComponents">'
        + '      <DetailLevel>ReturnAll</DetailLevel>'
        + '      <ErrorLanguage>en_GB</ErrorLanguage>'
        + '      <Version>945</Version>'
        {
        + '      <Search>'
        + '        <SearchType>SaleRecordID</SearchType>'
        + '        <SearchValue>' + '1981' + '</SearchValue>'
        + '      </Search>'
        }
        + '    <Archived>false</Archived>'
        + '    <SaleDateRange>'
        + '      <TimeFrom>2018-11-05T17:59:32.939+02:00</TimeFrom>'
        + '      <TimeTo>2018-11-06T23:59:59.940+01:00</TimeTo>'
        + '    </SaleDateRange>'
        + '  </GetSellingManagerSoldListingsRequest>'
        + '</SOAP-ENV:Body>';

  objHttpReqResp.URL := 'https://api.ebay.com/wsapi';

  sResponseBody := TStringStream.Create();
  try
    objHttpReqResp.Execute(sSOAP, sResponseBody);

    xDoc := TXMLDocument.Create(nil);
    xDoc.LoadFromStream(sResponseBody);
    xDoc.SaveToFile('XML_Output.txt');

    memHTML.Lines.LoadFromFile('XML_Output.txt');
    memHTML.Lines.Add('');
  except
    memHTML.Lines.Add('Error happened!');
    memHTML.Lines.Add('');
  end;
end;

返回结果为:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server.userException</faultcode>
            <faultstring>org.xml.sax.SAXParseException: XML document structures must start and end within the same entity.</faultstring>
            <detail/>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

是否意味着:

  1. 用户信息有误(Token/AppID/DevID/CertID)?
  2. 或者我的代码有问题混合了一些参数?

有什么建议吗? sToken 是卖家的 eBay 令牌,它只是从 Developer.ebay.com.

申请的

谢谢。

#

程序更新如下:

procedure TForm1.Button1Click(Sender: TObject);
var
  sXML: String;
  sCallName, sSiteID, sVersion: String;
  sResponseBody: TStringStream;
  xDoc: IXMLDocument;
  sSaleNo: String;
begin
  sCallName := 'GetSellingManagerSoldListingsRequest';
  sSiteID := '15';
  sVersion := '945';
  sSaleNo := '2000';

  sXML := '<?xml version="1.0"?>'
        + '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'
        + '  xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
        + '  <SOAP-ENV:Header>'
        + '    <NS1:RequesterCredentials xmlns:NS1="urn:ebay:apis:eBLBaseComponents">'
        + '      <eBayAuthToken xmlns="urn:ebay:apis:eBLBaseComponents">' + sToken + '</eBayAuthToken>'
        + '      <NS1:Credentials>'
        + '        <AppId xmlns="urn:ebay:apis:eBLBaseComponents">' + sAppID + '</AppId>'
        + '        <DevId xmlns="urn:ebay:apis:eBLBaseComponents">' + sDevID + '</DevId>'
        + '        <AuthCert xmlns="urn:ebay:apis:eBLBaseComponents">' + sCertID + '</AuthCert>'
        + '      </NS1:Credentials>'
        + '    </NS1:RequesterCredentials>'
        + '  </SOAP-ENV:Header>'
        + '  <SOAP-ENV:Body>'
        + '    <GetSellingManagerSoldListingsRequest xmlns="urn:ebay:apis:eBLBaseComponents">'
        + '      <Archived>false</Archived>'
        + '      <DetailLevel>ReturnAll</DetailLevel>'
        + '      <Filter>PaidNotShipped</Filter>'
        + '      <ErrorLanguage>en_AU</ErrorLanguage>'
        + '      <Version>' + sVersion + '</Version>'
        + '    </GetSellingManagerSoldListingsRequest>'
        + '  </SOAP-ENV:Body>'
        + '</SOAP-ENV:Envelope>';

  objHttpReqResp.URL := 'https://api.sandbox.ebay.com/wsapi'
                      + '?callname=' + sCallName
                      + '&siteid=' + sSiteID
                      + '&appid=' + sAppID
                      + '&version=' + sVersion
                      + '&routing=default';

  sResponseBody := TStringStream.Create();
  try
    objHttpReqResp.Execute(sXML, sResponseBody);

    xDoc := TXMLDocument.Create(nil);
    xDoc.LoadFromStream(sResponseBody);
    xDoc.SaveToFile('XML_Output.txt');

    memHTML.Lines.LoadFromFile('XML_Output.txt');
    memHTML.Lines.Add('');

    memHTML.Lines.Add(objHttpReqResp.URL);
    memHTML.Lines.Add('');
  except
    memHTML.Lines.Add('Error happened!');
    memHTML.Lines.Add('');
  end;
  sResponseBody.Free;
end;

现在错误信息更改为:

<faultcode>soapenv:Server.userException</faultcode>
<faultstring>
  com.ebay.app.pres.service.hosting.WebServiceDisabledException:
  The web service GetSellingManagerSoldListingsRequest is not properly
  configured or not found and is disabled.
</faultstring>

参考 faltstring,它说 "not properly configured"。我阅读了 eBay 开发人员文档 https://developer.ebay.com/devzone/xml/docs/reference/ebay/GetSellingManagerSoldListings.html#Request.Pagination.EntriesPerPage,但仍然不知道如何正确配置它。

看来您没有仔细阅读EBAY API documentationweb服务xxx不正常 配置或未找到并已禁用。 根据为 SOAP 调用提供链接。 您将 CallName 设为:

sCallName := 'GetSellingManagerSoldListingsRequest';

但应该是:

sCallName := 'GetSellingManagerSoldListings';

另外我认为除了 try...except 你应该使用 try...finally 块(或两者)。

考虑如果在您的通话期间出现异常会发生什么情况:

 var
    sResponseBody: TStringStream; 
 begin
 ...
 sResponseBody := TStringStream.Create();
    try
     objHttpReqResp.Execute(sXML, sResponseBody);

   xDoc := TXMLDocument.Create(nil);
   xDoc.LoadFromStream(sResponseBody);
   xDoc.SaveToFile('XML_Output.txt');

    memHTML.Lines.LoadFromFile('XML_Output.txt');
    memHTML.Lines.Add('');

    memHTML.Lines.Add(objHttpReqResp.URL);
    memHTML.Lines.Add('');
except
    memHTML.Lines.Add('Error happened!');
    memHTML.Lines.Add('');
end;
 sResponseBody.Free;

这一行:

 sResponseBody.Free;

永远不会执行,导致内存泄漏...

我不认为你是"dumb programmer",但可以清楚地看出你是一个没有经验的人:)

Stack Overflow 是词汇表而不是论坛,您应该考虑这一点。我强烈建议您阅读 How to ask section 以避免投票和 "rude" 评论和答案。

请注意,我在这里没有任何攻击性,您可能意识到我花了几天时间只是想帮助您,而您最终成功的信息是我能在那里赢得的最好奖品:)

亲切的问候