Delphi调用JAVA的WebService上传XML文件(XE10.2+WIN764)
相关资料:
1.http://blog.csdn.net/luojianfeng/article/details/51219890
2.http://blog.csdn.net/avsuper/article/details/8764165
注意事项:
1.生成WSDL文件时,D7可能有的无法生成,用XE版本可以全部生成。
返回字节流:
1 function GetByte(AString: string): TByteDynArray;
2 var
3 sByte: TByteDynArray;
4 begin
5 SetLength(sByte, Length(AString));
6 Move(AString[1], sbyte[0], Length(AString));
7 Result := sByte;
8 end;
实例代码:DELPHI以TByteDynArray(Bytes)方式传递图片到JAVA的WEBSERVICE保存
1 procedure TForm1.btn17Click(Sender: TObject);
2 var
3 strm : TMemoryStream;
4 AFileData: TByteDynArray;
5 fsize:Integer;
6 begin
7 strm := TMemoryStream.Create;
8 img1.Picture.Graphic.SaveToStream(strm);//把图片转化成内存流
9 strm.Position:=0;//切记,操作图片前一定要这句,否则错误
10 //把内存流转化成TByteDynArray
11 fsize:=strm.Size;
12 SetLength(AFileData,fsize);
13 strm.Read(AFileData[0],fsize);
14 addResult:=ServiceHello1.addUser_Byte(edt4.Text, AFileData);
15 if (addResult='ok') then
16 begin
17 ShowMessage('添加成功');
18 end;
19 end;
实例代码:在Delphi中怎么通过webservice上传文件,比较
1 var filename:string;
2 x:string;
3 MStream: TMemoryStream;
4 c: array of TByteDynArray;
5 begin
6 HTTPRIO1.HTTPWebNode.UseUTF8InHeader:=true;
7 HTTPRIO1.WSDLLocation:='http://localhost/grsb/pswService.asmx';
8 HTTPRIO1.Service:='pswService';
9 HTTPRIO1.Port:='pswServiceSoap';
10 HTTPDeclare:=HTTPRIO1 as pswServiceSoap;
11
12 MStream := TMemoryStream.Create;
13 try
14 if OpenDialog1.Execute then
15 begin
16 filename:=OpenDialog1.FileName;
17 MStream.LoadFromFile(filename);
18 MStream.Position := 0;
19 SetLength(c, MStream.size);
20 MStream.ReadBuffer(c[0], MStream.size);
21 x:=HTTPDeclare.zlUploadFile(c[0]);
22 //ShowMessage(x);
23 end;
24 finally
25 MStream.Free;
26 end;
27 end;
实例代码:Delphi调用JAVA的WebService上传XML文件
1 procedure TForm1.Button2Click(Sender: TObject);
2 const
3 sName = 'name';
4 sPassWord = 'pass';
5 sDateTime = '2017-11-12 19:41:00';
6 sCode = '610101';
7 sCode2 = '060611882';
8 var
9 iRTJSServicePortType: RTJSServicePortType;
10 ST:String;
11 sInfo: TByteDynArray;
12 P: PChar;
13 s: string;
14 oStream: TMemoryStream;
15 begin
16 //内存流方法
17 oStream := TMemoryStream.Create;
18 try
19 begin
20 oStream.LoadFromFile('aaa.xml');
21 oStream.Position := 0;
22 SetLength(sInfo, oStream.size);
23 // MStream.ReadBuffer(sInfo[0], MStream.size);
24 oStream.Read(sInfo[0], oStream.size);
25 iRTJSServicePortType := GetRTJSServicePortType;
26 s := iRTJSServicePortType.uploadInpRegister(sName, sPassWord, sDateTime, sCode, sCode2, sInfo);
27 ShowMessage(s);
28 end;
29 finally
30 oStream.Free;
31 end;
32 end;
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我