感谢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>
这是否意味着:
有什么建议吗? 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,但仍然不知道如何正确配置它。
答案 0 :(得分:1)
似乎您没有仔细阅读EBAY API documentation和The web service xxx is not properly configured or not found and is disabled. 根据提供用于SOAP调用的链接。 您将CallName设置为:
sCallName := 'GetSellingManagerSoldListingsRequest';
但应该是:
sCallName := 'GetSellingManagerSoldListings';
我还认为,除了尝试使用...以外,我不应该尝试使用...最终阻止(或两者同时使用)。
考虑在您的通话期间引发异常时会发生什么:
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,以避免投票不足和“粗鲁”的评论和答案。
请考虑到我在任何方面都不是一个有侵略性的人,您可能意识到我花了几天的时间试图帮助您,而您最终获得成功的信息是我可以在那里获得的最好奖赏:)
亲切的问候