delphi soapenv:Server.userException ->来自eBay Trading API GetSellingManagerSoldListingsRequest的错误

4urapxun  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(98)

感谢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)?
1.或者我的代码有问题,混合了一些参数?
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,但仍然不知道如何正确配置它。

km0tfn4u

km0tfn4u1#

看起来你没有仔细阅读EBAY API documentationThe web service xxx is not properly configured or not found and is disabled.,根据提供的SOAP调用链接。你把CallName作为:

sCallName := 'GetSellingManagerSoldListingsRequest';

字符串
但它应该是:

sCallName := 'GetSellingManagerSoldListings';


另外,我认为,而不是尝试...除了你应该使用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;


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

相关问题