通过WSDLimport引入WEBSERVICE,DELPHI会自动产生自定义的Header类,这个类继承于TSoapHeader。
ShuSoapHeader = class(TSOAPHeader)
private
FNMsg:WideString;
FUserID:WideString;
FPassWord:WideString;
published
propertyNMsg: WideString read FNMsg write FNMsg;
propertyUserID: WideString read FUserID write FUserID;
propertyPassWord: WideString read FPassWord write FPassWord;
end;
同时自动产生引用接口:
InvRegistry.RegisterInterface(TypeInfo(SLoginServicesSoap),'http://passport.shu.edu.cn/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(SLoginServicesSoap),'http://passport.shu.edu.cn/%operationName%');
InvRegistry.RegisterHeaderClass(TypeInfo(SLoginServicesSoap),ShuSoapHeader, 'ShuSoapHeader', '');
RemClassRegistry.RegisterXSClass(ShuSoapHeader,'http://passport.shu.edu.cn/', 'ShuSoapHeader');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfString),'http://passport.shu.edu.cn/', 'ArrayOfString');
客户端使用:
vari:integer;
aIntf: SLoginServicesSoap;
soaphead : ShuSoapHeader;
Headers: ISOAPHeaders;
begin
aIntf :=sLogin as SLoginServicesSoap;//THTTPRIO控件
soaphead:= ShuSoapHeader.Create;
soaphead.UserID :='';
soaphead.PassWord := '';
try
Headers := (aIntf as ISOAPHeaders);
Headers.Send(soaphead); //发送Soap Header
i:=aIntf.ValidByEd(Trim(Edit_name.Text),Trim(Edit_pass.Text));
finally
aIntf := nil;
soaphead.Free;
end;