用delphi 怎么调用用C#写的webservice?

flysky2006 2006-06-10 10:16:36
用delphi 怎么调用用C#写的webservice?
...全文
1420 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Enight 2006-09-05
  • 打赏
  • 举报
回复
DaXiaLv(爱睡觉的猪) 答案正确
DaXiaLv 2006-08-30
  • 打赏
  • 举报
回复
vs.net2005开发的话
要在delphi中加一句InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);
Enight 2006-08-21
  • 打赏
  • 举报
回复
失败,
服务端接收客户端传来的参数为NULL
helodd 2006-08-20
  • 打赏
  • 举报
回复
看以下的一个例子(转)

先用vs.net创建一个简单的webservices;

1.打开vs.net2003 新建一个webservises 命名为WebService1

2.添加两个WebMethod

[WebMethod]

public string HelloWorld()

{

return "Hello World 用.NET写的web服务!!^_^";

}

[WebMethod]

public string datetostr(DateTime dt)//将时间转换为字符

{

return dt.ToUniversalTime().ToString();

}

完整代码如下:

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Web;

using System.Web.Services;





namespace WebService1

{

public class Service1 : System.Web.Services.WebService

{

public Service1()

{

//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的

InitializeComponent();

}





#region 组件设计器生成的代码



//Web 服务设计器所必需的

private IContainer components = null;



/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if(disposing && components != null)

{

components.Dispose();

}

base.Dispose(disposing);

}



#endregion

[WebMethod]

public string HelloWorld()

{

return "Hello World 用.NET写的web服务!!^_^";

}

[WebMethod]

public string datetostr(DateTime dt)//将时间转换为字符

{

return dt.ToUniversalTime().ToString();

}

}

}

2.编译调试:





我们的webservices已经可以用了;





下面在打开delphi 7

新建一个应用程序:

拖两个button两个edit 和一个HTTPRIO(在webservices页上)到窗体上;

3.接下来:

File->new->other->webservices->WSDL importer

点击next 导入

保存unit Service1

4.在unit1(form1 的单元文件)中引用Service1, XSBuiltIns

5. HTTPRIO1的

WSDLLocation 属性设置为'http://localhost/WebService1/Service1.asmx?WSDL'

6.添加form1 的代码如下:

unit Unit1;



interface



uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, InvokeRegistry, Rio, SOAPHTTPClient;


type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

Edit1: TEdit;

Edit2: TEdit;

HTTPRIO1: THTTPRIO;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;


var

Form1: TForm1;


implementation

uses

XSBuiltIns,

Service1;

{$R *.dfm}





procedure TForm1.Button1Click(Sender: TObject);

var

dtm:TXSDateTime;

begin

dtm:=TXSDateTime.Create;

dtm:=DateTimeToXSDateTime(now);

Edit1.Text:=(HTTPRIO1 as Service1Soap).datetostr(dtm);

dtm.free;

end;





procedure TForm1.Button2Click(Sender: TObject);

begin

Edit2.Text:=(HTTPRIO1 as Service1Soap).HelloWorld;

end;



end.

7.编译运行
touchboy 2006-06-10
  • 打赏
  • 举报
回复
搜一下李维写的Delphi调用Web Service的文章
flysky2006 2006-06-10
  • 打赏
  • 举报
回复
各位能帮就帮一下?
又接触过的给点提示也可

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧