• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi调用WebServices(C#)代码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

using System.Data;
using System.Data.OracleClient;
using System.IO;

using System.IO.Compression;
using System.Runtime.Serialization.Formatters.Binary;
[WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
}
以上为webservice客户端代码;下面是delphi代码:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, InvokeRegistry, Rio, SOAPHTTPClient, ExtCtrls, StdCtrls,
  Service,types,jpeg,StrUtils, Buttons;
  
//StrUtils:取指定字符
  {QDialogs:在delphi6及以后的版本中,
  为了支持kylix,能使程序在linux下运行
  每一个单元都增加了对应的QDialogs单元
  如果你用了带Q的单元,哪么如果你的程序
  要想在Windows中正常运行必须得有qtintf.dll
  的支持你可以搜索一个,把程序中uses中的
  单元前有Q的把Q去掉就ok了!   }

type
  TForm1 
= class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Panel1: TPanel;
    Image1: TImage;
    HTTPRIO1: THTTPRIO;
    
Open: TOpenDialog;
    Search: TButton;
    
Add: TButton;
    
Update: TButton;
    
Delete: TButton;
    Panel2: TPanel;
    Image2: TImage;
    Label2: TLabel;
    
procedure SearchClick(Sender: TObject);
    
procedure FormShow(Sender: TObject);
    
procedure Image2Click(Sender: TObject);
    
procedure Edit1KeyPress(Sender: TObject; var KeyChar);
    
procedure Image1Click(Sender: TObject);
    
procedure AddClick(Sender: TObject);
    
procedure DeleteClick(Sender: TObject);
    
procedure UpdateClick(Sender: TObject);

  private
    { Private declarations }
  
public
    { 
Public declarations }
  
end;

var
  Form1: TForm1;
  files:TFileStream;
  ms:TMemoryStream;
  jpg:TjpegImage;
  s:TByteDynArray;
  path:WideString;
implementation

{$R 
*.dfm}

procedure TForm1.SearchClick(Sender: TObject);
var
  bmTemp:TjpegImage;
//TBitmap;
  Web_Search:ServiceSoap;
begin
     bmTemp:
=TjpegImage.Create;
      
//创建流
      ms:
=TMemoryStream.Create;
    Web_Search:
=HTTPRIO1 as ServiceSoap;
   try
      
if (edit1.Text<>''then
          
begin
             
//调用服务查询功能
              s:
=(Web_Search.Search(edit1.Text));
              
if(length(s)<6229)  then
                  
begin
                     showmessage(
'没有图片,请重输');
                     image1.Picture.Assign(nil);
                  
end
              
else
                  
begin
                     
//从图片开始位置读取
                     ms.Write(s
[6229],length(s));
                     ms.Position:
=0;
                     
//加载流
                     bmTemp.LoadFromStream(ms);
                      
//输出
                     image1.Picture.Assign(bmTemp);
                  
end;

            
end
       
else
          
begin
              showmessage(
'缺少查询条件!');
              image1.Picture.Assign(nil);
              edit1.SetFocus;
          
end;
   finally
       
//释放空间
       ms.Free;
       bmTemp.Free;
       
//控制
       
//edit1.Clear;
       edit1.SetFocus;
    
end;

 
end;
procedure TForm1.FormShow(Sender: TObject);
var
    fstyle: dWord;
begin
     
//控制edit只输入数字
     fstyle :
= GetWindowLong(Edit1.Handle, GWL_STYLE);
     SetWindowLong(Edit1.Handle, GWL_STYLE, fstyle 
or ES_NUMBER);
      
//指定图片格式
     edit1.SetFocus;
     
end;

procedure TForm1.Image2Click(Sender: TObject);
var
 Web_link:ServiceSoap;
begin
  
//测试连接
   Web_link:
=HTTPRIO1 as ServiceSoap;
   showmessage(
''+Web_link.Linking+'');
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var KeyChar);
begin
   
//输入控制
   
if key=#13 then
   Search.Click;
end;

procedure TForm1.Image1Click(Sender: TObject);
var
  testpath:string;
  testname:string;
begin
  ms:
=TMemoryStream.Create;
  jpg:
=TjpegImage.Create;
  
if Open.Execute then
     
begin
       testpath:
=ExtractFileName(open.FileName);
       testname:
=RightStr(testpath,4);
       
if (testname='.jpg')or( testname='.JPG'or( testname='.jpeg')or( testname='.JPEG')then
           
begin
              path:
=ExtractFileDir(open.FileName)+'\'+ExtractFileName(open.FileName);
              files:
= TFileStream.Create(open.FileName,fmShareDenyWrite);
              try
                  jpg.LoadFromStream(files);
                  jpg.SaveToStream(ms);
                  image1.Picture.Assign(jpg);
              finally
                  files.Free;
               
end;
            
end
        
else
        showmessage(
'当前默认为JPEG类型图片');
    
end;
end;
end.


 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab 生成图像,直接导出到excel, word(转载)发布时间:2022-07-18
下一篇:
Matlab GUI保存图片发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap