Delphi调用JAVA的WebService上传XML文件(XE10.2+WIN764)

时间:2023-02-08 13:48:26

相关资料:
1.http://blog.csdn.net/luojianfeng/article/details/51219890
2.http://blog.csdn.net/avsuper/article/details/8764165

注意事项:

1.生成WSDL文件时,D7可能有的无法生成,用XE版本可以全部生成。

返回字节流:

   function GetByte(AString: string): TByteDynArray;
var
sByte: TByteDynArray;
begin
SetLength(sByte, Length(AString));
Move(AString[], sbyte[], Length(AString));
Result := sByte;
end;

实例代码:DELPHI以TByteDynArray(Bytes)方式传递图片到JAVA的WEBSERVICE保存

 procedure TForm1.btn17Click(Sender: TObject);
var
strm : TMemoryStream;
AFileData: TByteDynArray;
fsize:Integer;
begin
strm := TMemoryStream.Create;
img1.Picture.Graphic.SaveToStream(strm);//把图片转化成内存流
strm.Position:=;//切记,操作图片前一定要这句,否则错误
//把内存流转化成TByteDynArray
fsize:=strm.Size;
SetLength(AFileData,fsize);
strm.Read(AFileData[],fsize);
addResult:=ServiceHello1.addUser_Byte(edt4.Text, AFileData);
if (addResult='ok') then
begin
ShowMessage('添加成功');
end;
end;

实例代码:在delPhi中怎么通过webservice上传文件,比较

 var filename:string;
x:string;
MStream: TMemoryStream;
c: array of TByteDynArray;
begin
HTTPRIO1.HTTPWebNode.UseUTF8InHeader:=true;
HTTPRIO1.WSDLLocation:='http://localhost/grsb/pswService.asmx';
HTTPRIO1.Service:='pswService';
HTTPRIO1.Port:='pswServiceSoap';
HTTPDeclare:=HTTPRIO1 as pswServiceSoap; MStream := TMemoryStream.Create;
try
if OpenDialog1.Execute then
begin
filename:=OpenDialog1.FileName;
MStream.LoadFromFile(filename);
MStream.Position := ;
SetLength(c, MStream.size);
MStream.ReadBuffer(c[], MStream.size);
x:=HTTPDeclare.zlUploadFile(c[]);
//ShowMessage(x);
end;
finally
MStream.Free;
end;
end;

实例代码:Delphi调用JAVA的WebService上传XML文件

 procedure TForm1.Button2Click(Sender: TObject);
const
sName = 'name';
sPassWord = 'pass';
sDateTime = '2017-11-12 19:41:00';
sCode = '';
sCode2 = '';
var
iRTJSServicePortType: RTJSServicePortType;
ST:String;
sInfo: TByteDynArray;
P: PChar;
s: string;
oStream: TMemoryStream;
begin
//内存流方法
oStream := TMemoryStream.Create;
try
begin
oStream.LoadFromFile('aaa.xml');
oStream.Position := ;
SetLength(sInfo, oStream.size);
// MStream.ReadBuffer(sInfo[0], MStream.size);
oStream.Read(sInfo[], oStream.size);
iRTJSServicePortType := GetRTJSServicePortType;
s := iRTJSServicePortType.uploadInpRegister(sName, sPassWord, sDateTime, sCode, sCode2, sInfo);
ShowMessage(s);
end;
finally
oStream.Free;
end;
end;