はじめまして、こんにちは。
Delphiを勉強中の衣里と言います。
Delphi2007 Enterprise アカデミック Update3を使っています。
SOAPに興味があり、現在勉強しています。
SOAPの仕組みのイメージは沸いたのですが実際のコーディングで行き詰まっています。
# 題材(SOAPサーバー)は何でも良いのですが、
# ググって見つかったYahoo!オークションのSOAPを試しに利用しようと思っています。
# (http://developer.yahoo.co.jp/auctions/all/V1/soap/all.html)
# なお、ヤフオク用ツールを作りたいとは思っていないので他に簡易な題材があれば、
# 変更しても構いません(笑)
現在、WSDLのインポートは完了し「yahooAuctionService.pas」が生成されています。
(http://soap.auctions.yahoo.co.jp/AuctionWSDL/V1/yahooAuctionService.wsdl)
次に、オークションID(?)「v29974472」のタイトルを取得してみようと思い「yahooAuctionService.pas」を覗いているのですが、利用法がさっぱり検討がつきません。
どのようにコードを書いたら良いのでしょう。
ご存じの方、いらっしゃいましたらよろしくお願いします。
yahooAuctionService.pasのファイルサイズは大きいのかな?
それの内容を見れば、利用方法も分かると思うけど。
そうねぇさん、ありがとうございます!
330行もあります…ここに貼り付くでしょうか…試してみます。
----------------------------
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://soap.auctions.yahoo.co.jp/AuctionWSDL/V1/yahooAuctionService.wsdl
// >Import : http://soap.auctions.yahoo.co.jp/AuctionWSDL/V1/yahooAuctionService.wsdl:0
// Encoding : UTF-8
// Version : 1.0
// (2007/10/11 9:37:59 - - $Rev: 7300 $)
// ************************************************************************ //
unit yahooAuctionService;
interface
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;
const
IS_OPTN = $0001;
type
// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:int - "http://www.w3.org/2001/XMLSchema"[Gbl]
// !:string - "http://www.w3.org/2001/XMLSchema"[Gbl]
// !:boolean - "http://www.w3.org/2001/XMLSchema"[Gbl]
// !:long - "http://www.w3.org/2001/XMLSchema"[Gbl]
childCategory = class; { "urn:yahoo:jp:auction:soap"[GblCplx] }
summary = class; { "urn:yahoo:jp:auction:soap"[GblCplx] }
listingParameter = class; { "urn:yahoo:jp:auction:soap"[GblCplx] }
// ************************************************************************ //
// XML : childCategory, global, <complexType>
// Namespace : urn:yahoo:jp:auction:soap
// ************************************************************************ //
childCategory = class(TRemotable)
private
FcategoryID: Integer;
FcategoryName: WideString;
FcategoryName_Specified: boolean;
FnumOfAuctions: Integer;
FisLeaf: Boolean;
procedure SetcategoryName(Index: Integer; const AWideString: WideString);
function categoryName_Specified(Index: Integer): boolean;
published
property categoryID: Integer read FcategoryID write FcategoryID;
property categoryName: WideString Index (IS_OPTN) read FcategoryName write SetcategoryName stored categoryName_Specified;
property numOfAuctions: Integer read FnumOfAuctions write FnumOfAuctions;
property isLeaf: Boolean read FisLeaf write FisLeaf;
end;
// ************************************************************************ //
// XML : summary, global, <complexType>
// Namespace : urn:yahoo:jp:auction:soap
// ************************************************************************ //
summary = class(TRemotable)
private
FauctionID: WideString;
FauctionID_Specified: boolean;
Ftitle: WideString;
Ftitle_Specified: boolean;
Fseller: WideString;
Fseller_Specified: boolean;
Fimage: WideString;
Fimage_Specified: boolean;
FcategoryID: Integer;
Fduration: Integer;
Fprice: Int64;
FnumBids: Integer;
FendTime: Int64;
Fbidorbuy: Int64;
FisReserved: Boolean;
FisNew: Boolean;
FisStore: Boolean;
FisPublic: Boolean;
FisCheck: Boolean;
FisFreeShipping: Boolean;
FisEscrow: Boolean;
FisWrapping: Boolean;
FisBuyNow: Boolean;
FisEasyPayment: Boolean;
FisLargeImage: Boolean;
FgiftIcon: WideString;
FgiftIcon_Specified: boolean;
procedure SetauctionID(Index: Integer; const AWideString: WideString);
function auctionID_Specified(Index: Integer): boolean;
procedure Settitle(Index: Integer; const AWideString: WideString);
function title_Specified(Index: Integer): boolean;
procedure Setseller(Index: Integer; const AWideString: WideString);
function seller_Specified(Index: Integer): boolean;
procedure Setimage(Index: Integer; const AWideString: WideString);
function image_Specified(Index: Integer): boolean;
procedure SetgiftIcon(Index: Integer; const AWideString: WideString);
function giftIcon_Specified(Index: Integer): boolean;
published
property auctionID: WideString Index (IS_OPTN) read FauctionID write SetauctionID stored auctionID_Specified;
property title: WideString Index (IS_OPTN) read Ftitle write Settitle stored title_Specified;
property seller: WideString Index (IS_OPTN) read Fseller write Setseller stored seller_Specified;
property image: WideString Index (IS_OPTN) read Fimage write Setimage stored image_Specified;
property categoryID: Integer read FcategoryID write FcategoryID;
property duration: Integer read Fduration write Fduration;
property price: Int64 read Fprice write Fprice;
property numBids: Integer read FnumBids write FnumBids;
property endTime: Int64 read FendTime write FendTime;
property bidorbuy: Int64 read Fbidorbuy write Fbidorbuy;
property isReserved: Boolean read FisReserved write FisReserved;
property isNew: Boolean read FisNew write FisNew;
property isStore: Boolean read FisStore write FisStore;
property isPublic: Boolean read FisPublic write FisPublic;
property isCheck: Boolean read FisCheck write FisCheck;
property isFreeShipping: Boolean read FisFreeShipping write FisFreeShipping;
property isEscrow: Boolean read FisEscrow write FisEscrow;
property isWrapping: Boolean read FisWrapping write FisWrapping;
property isBuyNow: Boolean read FisBuyNow write FisBuyNow;
property isEasyPayment: Boolean read FisEasyPayment write FisEasyPayment;
property isLargeImage: Boolean read FisLargeImage write FisLargeImage;
property giftIcon: WideString Index (IS_OPTN) read FgiftIcon write SetgiftIcon stored giftIcon_Specified;
end;
// ************************************************************************ //
// XML : listingParameter, global, <complexType>
// Namespace : urn:yahoo:jp:auction:soap
// ************************************************************************ //
listingParameter = class(TRemotable)
private
Fpage: Integer;
Fstore: Boolean;
Fescrow: Boolean;
Feasypayment: Boolean;
Fnewitems: Boolean;
Flargeimg: Boolean;
Ffreeshipping: Boolean;
Fwrappingicon: Boolean;
Fbuynow: Boolean;
Fthumbnail: Boolean;
Fattn: Boolean;
FgiftIcon: Integer;
Fsort: WideString;
Fsort_Specified: boolean;
Forder: WideString;
Forder_Specified: boolean;
procedure Setsort(Index: Integer; const AWideString: WideString);
function sort_Specified(Index: Integer): boolean;
procedure Setorder(Index: Integer; const AWideString: WideString);
function order_Specified(Index: Integer): boolean;
published
property page: Integer read Fpage write Fpage;
property store: Boolean read Fstore write Fstore;
property escrow: Boolean read Fescrow write Fescrow;
property easypayment: Boolean read Feasypayment write Feasypayment;
property newitems: Boolean read Fnewitems write Fnewitems;
property largeimg: Boolean read Flargeimg write Flargeimg;
property freeshipping: Boolean read Ffreeshipping write Ffreeshipping;
property wrappingicon: Boolean read Fwrappingicon write Fwrappingicon;
property buynow: Boolean read Fbuynow write Fbuynow;
property thumbnail: Boolean read Fthumbnail write Fthumbnail;
property attn: Boolean read Fattn write Fattn;
property giftIcon: Integer read FgiftIcon write FgiftIcon;
property sort: WideString Index (IS_OPTN) read Fsort write Setsort stored sort_Specified;
property order: WideString Index (IS_OPTN) read Forder write Setorder stored order_Specified;
end;
// ************************************************************************ //
// Namespace : urn:yahoo:jp:auction:soap
// transport : http://schemas.xmlsoap.org/soap/http
// style : rpc
// binding : yahooAuctionService
// service : yahooAuctionService
// port : yahooAuctionService
// URL : http://soap.auctions.yahoo.co.jp/AuctionSOAP/V1
// ************************************************************************ //
yahooAuctionServicePortType = interface(IInvokable)
['{D8504092-B0EF-3D64-F0A1-EC497227ED3D}']
procedure getCategory(var categoryID: Integer; out categoryName: WideString; out categoryPath: WideString; out parentCategoryPath: WideString; out isLeaf: Boolean; out childCategoryNum: Integer;
out item: childCategory); stdcall;
procedure getCategoryItems(var categoryID: Integer; const param: listingParameter; out totalFAuctions: Integer; out totalAuctions: Integer; out totalPage: Integer; out curPage: Integer;
out categoryPath: WideString; out item: summary); stdcall;
procedure getSellingList(const sellerID: WideString; const param: listingParameter; out totalAuctions: Integer; out totalPage: Integer; out curPage: Integer; out item: summary
); stdcall;
end;
function GetyahooAuctionServicePortType(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): yahooAuctionServicePortType;
implementation
uses SysUtils;
function GetyahooAuctionServicePortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): yahooAuctionServicePortType;
const
defWSDL = 'http://soap.auctions.yahoo.co.jp/AuctionWSDL/V1/yahooAuctionService.wsdl';
defURL = 'http://soap.auctions.yahoo.co.jp/AuctionSOAP/V1';
defSvc = 'yahooAuctionService';
defPrt = 'yahooAuctionService';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as yahooAuctionServicePortType);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
procedure childCategory.SetcategoryName(Index: Integer; const AWideString: WideString);
begin
FcategoryName := AWideString;
FcategoryName_Specified := True;
end;
function childCategory.categoryName_Specified(Index: Integer): boolean;
begin
Result := FcategoryName_Specified;
end;
procedure summary.SetauctionID(Index: Integer; const AWideString: WideString);
begin
FauctionID := AWideString;
FauctionID_Specified := True;
end;
function summary.auctionID_Specified(Index: Integer): boolean;
begin
Result := FauctionID_Specified;
end;
procedure summary.Settitle(Index: Integer; const AWideString: WideString);
begin
Ftitle := AWideString;
Ftitle_Specified := True;
end;
function summary.title_Specified(Index: Integer): boolean;
begin
Result := Ftitle_Specified;
end;
procedure summary.Setseller(Index: Integer; const AWideString: WideString);
begin
Fseller := AWideString;
Fseller_Specified := True;
end;
function summary.seller_Specified(Index: Integer): boolean;
begin
Result := Fseller_Specified;
end;
procedure summary.Setimage(Index: Integer; const AWideString: WideString);
begin
Fimage := AWideString;
Fimage_Specified := True;
end;
function summary.image_Specified(Index: Integer): boolean;
begin
Result := Fimage_Specified;
end;
procedure summary.SetgiftIcon(Index: Integer; const AWideString: WideString);
begin
FgiftIcon := AWideString;
FgiftIcon_Specified := True;
end;
function summary.giftIcon_Specified(Index: Integer): boolean;
begin
Result := FgiftIcon_Specified;
end;
procedure listingParameter.Setsort(Index: Integer; const AWideString: WideString);
begin
Fsort := AWideString;
Fsort_Specified := True;
end;
function listingParameter.sort_Specified(Index: Integer): boolean;
begin
Result := Fsort_Specified;
end;
procedure listingParameter.Setorder(Index: Integer; const AWideString: WideString);
begin
Forder := AWideString;
Forder_Specified := True;
end;
function listingParameter.order_Specified(Index: Integer): boolean;
begin
Result := Forder_Specified;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(yahooAuctionServicePortType), 'urn:yahoo:jp:auction:soap', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(yahooAuctionServicePortType), '');
RemClassRegistry.RegisterXSClass(childCategory, 'urn:yahoo:jp:auction:soap', 'childCategory');
RemClassRegistry.RegisterXSClass(summary, 'urn:yahoo:jp:auction:soap', 'summary');
RemClassRegistry.RegisterXSClass(listingParameter, 'urn:yahoo:jp:auction:soap', 'listingParameter');
end.
例えば、カテゴリに関する情報を取得するなら、categoryIDを指定して
GetCategory手続きを呼び出すと、categoryName, categoryPathなどの引数に
その値が返って来ることになるかな...
直接オークションIDを指定して、その情報を取得する関数はないような...
uses YahooAuctionService;
procedure TForm1.Button1Click(Sender: TObject);
var
YahooAuction: YahooAuctionServicePortType;
categoryID: Integer;
categoryName: WideString;
categoryPath: WideString;
parentCategoryPath: WideString;
IsLeaf: Boolean;
childCategoryNum: Integer;
item: childCategory;
ChildCategoryID: array of Integer;
ChildCategoryName: array of WideString;
ChildNumOfAuctions: array of Integer;
ChildIsLeaf: array of Boolean;
i: Integer;
begin
YahooAuction := GetyahooAuctionServicePortType(False{True}, '', nil);
YahooAuction.GetCategory(categoryID, categoryName, categoryPath, parentCategoryPath, isLeaf, childCategoryNum, item);
SetLength(ChildCategoryID, ChildNumOfAuctions);
SetLength(ChildCategoryName, ChildNumOfAuctions);
SetLength(ChildNumOfAuctions, ChildNumOfAuctions);
SetLength(ChildIsLeaf, ChildNumOfAuctions);
for i:=0 to ChildNumOfAuctions-1 do begin
ChildCategoryID[i] := item.resultElements[i].categoryID;
ChildCategoryName[i] := item.resultElements[i].categoryName;
ChildNumOfAuctions[i] := item.resultElements[i].numOfAuctions;
ChildIsLeaf[i] := item.resultElements[i].isLeaf;
end;
end;
SetLength(ChildCategoryID, ChildNumOfAuctions);
...
ここらのChildNumOfAuctionsは、childCategoryNumの間違いだね。
試してないので他にも書き間違いがあるかも、まあ、コード例ということで。
さっそく有難うございます!!(涙
>ChildNumOfAuctionsは、childCategoryNumの間違いだね。
じつは、そこの部分のエラーでつまずいていて、
yahooAuctionService.pasとにらめっこしていました(^^;;
childCategoryNumに変更したらクリアしました!(^-^)
今、その後の部分でつまずいています。
具体的には、下記4行で、
>ChildCategoryID[i] := item.resultElements[i].categoryID;
>ChildCategoryName[i] := item.resultElements[i].categoryName;
>ChildNumOfAuctions[i] := item.resultElements[i].numOfAuctions;
>ChildIsLeaf[i] := item.resultElements[i].isLeaf;
[DCC エラー] Unit1.pas(51): E2003 未定義の識別子 : 'resultElements'
[DCC エラー] Unit1.pas(51): E2066 演算子またはセミコロン (';') が必要です
とエラーが出る状況です。
まだ、「何をしているか」が把握できていないため、
どうなおせば良いのか考えています。
もし、宜しければ、またアドバイスお願い致します。
ツイート | ![]() |