我有一个从wdsl文件生成的大单元,它无法公开soap标头以进行参数化。我需要在TRemotable查询中放置一个自定义soap标头。
gepirRequestHeader = class(TSOAPHeader)
private
FrequesterGln: string;
FrequesterGln_Specified: boolean;
Fcascade: Integer;
Fcascade_Specified: boolean;
procedure SetrequesterGln(Index: Integer; const Astring: string);
function requesterGln_Specified(Index: Integer): boolean;
procedure Setcascade(Index: Integer; const AInteger: Integer);
function cascade_Specified(Index: Integer): boolean;
published
property requesterGln: string Index (IS_OPTN) read FrequesterGln write SetrequesterGln stored requesterGln_Specified;
property cascade: Integer Index (IS_OPTN) read Fcascade write Setcascade stored cascade_Specified;
end;
我需要以某种方式将其注入像这样的对象
GetOwnerOfGLN = class(TRemotable)
private
Fversion: TXSDecimal;
Fversion_Specified: boolean;
FrequestedGln: ArrayOfString;
FrequestedGln_Specified: boolean;
FrequestedLanguages: ArrayOfLanguage;
FrequestedLanguages_Specified: boolean;
procedure Setversion(Index: Integer; const ATXSDecimal: TXSDecimal);
function version_Specified(Index: Integer): boolean;
procedure SetrequestedGln(Index: Integer; const AArrayOfString: ArrayOfString);
function requestedGln_Specified(Index: Integer): boolean;
procedure SetrequestedLanguages(Index: Integer; const AArrayOfLanguage: ArrayOfLanguage);
function requestedLanguages_Specified(Index: Integer): boolean;
public
constructor Create; override;
destructor Destroy; override;
published
property version: TXSDecimal Index (IS_ATTR or IS_OPTN) read Fversion write Setversion stored version_Specified;
property requestedGln: ArrayOfString Index (IS_OPTN or IS_UNBD) read FrequestedGln write SetrequestedGln stored requestedGln_Specified;
property requestedLanguages: ArrayOfLanguage Index (IS_OPTN) read FrequestedLanguages write SetrequestedLanguages stored requestedLanguages_Specified;
end;
我知道理论上可以通过按摩ObjectToSoap中的xml来实现,但是可以通过可用对象干净地完成它吗?如果是这样,怎么样?
答案 0 :(得分:0)
嗯,这不是字符串操作,它看起来像shite,但它的工作原理 必须有一个更清洁的方法来做到这一点!?
我没有让查询soap类继承自TRemotable,而是创建了一个添加了
的TGepirQueryTGepirQuery = class(TRemotable)
private
class var Fcascades: Integer;
class var FGLN: String;
var
FRequestHeader: gepirRequestHeader;
class procedure Setcascades(const Value: Integer); static;
class procedure SetGLN(const Value: String); static;
public
constructor Create; override;
class constructor CreateTGepirResponse;
destructor Destroy; override;
function ObjectToSOAP(RootNode, ParentNode: IXMLNode;
const ObjConverter: IObjConverter;
const NodeName, NodeNamespace, ChildNamespace: InvString; ObjConvOpts: TObjectConvertOptions;
out RefID: InvString): IXMLNode; override;
class property GLN:String read FGLN write SetGLN;
class property cascades: Integer read Fcascades write Setcascades;
property RequestHeader: gepirRequestHeader read FRequestHeader write FRequestHeader;
published
end;
ObjectToSoap覆盖有点毛茸茸......
function TGepirQuery.ObjectToSOAP(RootNode, ParentNode: IXMLNode; const ObjConverter: IObjConverter; const NodeName,
NodeNamespace, ChildNamespace: InvString; ObjConvOpts: TObjectConvertOptions; out RefID: InvString): IXMLNode;
var
SoapHeader: IXMLNode;
begin
SoapHeader := RootNode.ParentNode.AddChild('SOAP-ENV:Header', 0);
RequestHeader.ObjectToSOAP(RootNode, SoapHeader, ObjConverter, RequestHeader.ClassName, '', '',
[ocoDontPrefixNode, ocoDontPutTypeAttr], RefID);
Result := inherited ObjectToSoap(RootNode, ParentNode, objConverter, NodeName, NodeNameSpace, ChildNameSpace, ObjConvOpts, RefID);
end;
并且输出“装饰”很多命名空间垃圾,严格来说不需要在那里。
我的结果:
<?xml version="1.0" encoding="UTF-8"?>
<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:gepirRequestHeader xmlns:NS1="http://www.gepir.org/">
<requesterGln xmlns="http://www.gepir.org/">7080000366668</requesterGln>
<cascade xmlns="http://www.gepir.org/">9</cascade>
</NS1:gepirRequestHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<GetItemByGTIN xmlns="http://www.gepir.org/">
<requestedGtin>07037211110016</requestedGtin>
</GetItemByGTIN>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
每份文件的首选表格
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Header>
<gepirRequestHeader xmlns="http://www.gepir.org/">
<requesterGln>string</requesterGln>
<cascade>int</cascade>
</gepirRequestHeader>
</soap12:Header>
<soap12:Body>
<GetItemByGTIN version="decimal" xmlns="http://www.gepir.org/">
<requestedGtin>string</requestedGtin>
<requestedLanguages>
<language>language</language>
<language>language</language>
</requestedLanguages>
</GetItemByGTIN>
</soap12:Body>
</soap12:Envelope>