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

Posted 疯狂delphi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
View Code

 

实例代码: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;
View Code

 

实例代码:在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;
View Code

 

实例代码: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;
View Code

 

以上是关于Delphi调用JAVA的WebService上传XML文件(XE10.2+WIN764)的主要内容,如果未能解决你的问题,请参考以下文章

Delphi 调用WebService 直接发送SOPA报文

Delphi 调用WebService 直接发送SOPA报文

Delphi调用webservice总结

java调用java编写的WebService接口服务端收到的参数为空

如何在网页中调用webservice?

delphi 调用百度地图WEBSERVICE转换GPS坐标 转