【问题标题】:soapenv:Server.userException -> error from eBay Trading API GetSellingManagerSoldListingsRequestsoapenv:Server.userException -> 来自 eBay 交易 API GetSellingManagerSoldListingsRequest 的错误
【发布时间】:2018-11-07 09:21:56
【问题描述】:

感谢Vancalar的建议和XML代码(参考:eBay Trading API - calling structure in Delphi),我做了一个测试程序如下:

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,它显示“未正确配置”。我阅读了 eBay 开发者文档https://developer.ebay.com/devzone/xml/docs/reference/ebay/GetSellingManagerSoldListings.html#Request.Pagination.EntriesPerPage,但仍然不知道如何正确配置它。

【问题讨论】:

  • 添加最后一行: 因为我放的空格太少,所以它从我的回答中“消失”了 :)
  • 另外,您的 URL 应如下所示:https://api.ebay.com/wsapi?callname=GetSellingManagerSoldListings&siteid=15&appid=YourAppId&version=945&routing=default(删除“https://”和网址的其余部分)
  • 非常感谢,Vancalar。我马上试试。
  • 现在出现不同的错误消息:schemas.xmlsoap.org/soap/envelope" xmlns:xsd="@987654324 @" xmlns:xsi="w3.org/2001/XMLSchema-instance"> soapenv:Server.userExceptioncom.ebay.app.pres.service.hosting.WebServiceDisabledException : Web 服务 eBayAPI 未正确配置或未找到并被禁用。
  • 顺便说一下,我一步一步运行程序,URL在“https://”和其余部分之间没有一个空格。我不知道它是怎么发生的。

标签: delphi ebay-api


【解决方案1】:

看来你没有仔细阅读EBAY API documentationThe web service xxx is not properly configured or not found and is disabled. 根据为 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;

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

我不认为你是“愚蠢的程序员”,但可以清楚地看到你是一个没有经验的人:)

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

请考虑到我在这里并没有以任何方式咄咄逼人,您可能意识到我花了几天时间只是想帮助您,您最终成功的信息是我可以在那里赢得的最佳奖品 :)

亲切的问候

【讨论】:

  • 我需要再说一次“再次感谢您”。我确实意识到我应该对编码和研究更有耐心。阅读如何让我在这里不要太粗鲁应该对我有所帮助。也谢谢大家。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-07
  • 1970-01-01
  • 2014-02-08
  • 1970-01-01
  • 1970-01-01
  • 2016-05-14
相关资源
最近更新 更多