客户程序:
第一步:新建一个Application。

第二步:File----->New----->Other------>WebServices----->WSDL Importer

然后在Location of WSDL File or URL中填入:

http://10.22.30.61:36601/MonitorService.asmx?wsdl

或 http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl,然后确定即生成了一个新的接口定义单元。

第二步:在主form上放上一个按钮和一个Httprio组件(在WebServices页上),并引用第二个单元(即通过WSDL Importer自动生成的单元)

在Httprio的属性页上的WsdlLocation里面填上http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl;然后在Httprio属性页上的Port和Service上选择上相应的数据即可。

第三步:书写客户调用程序,原代码如下:

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  TMP_Weather: ArrayOfString;
begin
  //http://developer.51cto.com/art/200908/147125.htm
  //http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
  TMP_Weather := (HTTPRIO1 as WeatherWebServiceSoap).getWeatherbyCityName('53698'); //石家庄

Memo1.Lines.Clear;
  for i := 0 to 22 do
  begin
    Memo1.Lines.Add(TMP_Weather[i]);
  end;
end;

---- 错误信息为:
Project Project1.exe raised exception class ERemotableException with message '服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。'. Process stopped. Use Step or Run to continue.

------解决方案--------------------------------------------------------
修改一下WeatherWebService.pas这个单元,如下所示,一切就OK啦。

Delphi(Pascal) code

if HTTPRIO = nil then    RIO := THTTPRIO.Create(nil)  else    RIO := HTTPRIO;     RIO.HTTPWebNode.UseUTF8InHeader:= True;  //这里加上这一句  try    Result := (RIO as TestStationSoap);    if UseWSDL then    begin      RIO.WSDLLocation := Addr;      RIO.Service := defSvc;      RIO.Port := defPrt;    end else      RIO.URL := Addr;  finally    if (Result = nil) and (HTTPRIO = nil) then      RIO.Free;  end;    InvRegistry.RegisterInterface(TypeInfo(WeatherWebServiceSoap), 'http://WebXml.com.cn/', 'utf-8');  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(WeatherWebServiceSoap), 'http://WebXml.com.cn/%operationName%');  RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfString), 'http://WebXml.com.cn/', 'ArrayOfString');  RemClassRegistry.RegisterXSClass(getSupportDataSetResult, 'http://WebXml.com.cn/', 'getSupportDataSetResult');    InvRegistry.RegisterInvokeOptions(TypeInfo(WeatherWebServiceSoap), ioDocument);//这里加上这一句------解决方案--------------------------------------------------------补充一下,如果你用到HTTPRIO1去调webservice接口那就记得在前面加上这句HTTPRIO1.HTTPWebNode.UseUTF8InHeader:= True;//解决汉字乱码问题

本文出自:http://blog.csdn.net/gjtao1130/article/details/12193235  只是做部分修正。

//-------------以下是本人模仿的例子,窗体没有用到Httprio组件,通过GetWeatherWebServiceSoap函数处理即可。

 // ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2014/12/10 11:28:28 - 1.33.2.5)
// ************************************************************************ // unit WeatherWebService; interface uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns; type // ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema" getSupportDataSetResult = class; { "http://WebXml.com.cn/" } ArrayOfString = array of WideString; { "http://WebXml.com.cn/" } // ************************************************************************ //
// Namespace : http://WebXml.com.cn/
// ************************************************************************ //
getSupportDataSetResult = class(TRemotable)
private
Fschema: WideString;
published
property schema: WideString read Fschema write Fschema;
end; // ************************************************************************ //
// Namespace : http://WebXml.com.cn/
// soapAction: http://WebXml.com.cn/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : WeatherWebServiceSoap
// service : WeatherWebService
// port : WeatherWebServiceSoap
// URL : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
// ************************************************************************ //
WeatherWebServiceSoap = interface(IInvokable)
['{0AF62441-3FA0-F5D8-B6B8-B486F32F9DDE}']
function getSupportCity(const byProvinceName: WideString): ArrayOfString; stdcall;
function getSupportProvince: ArrayOfString; stdcall;
function getSupportDataSet: getSupportDataSetResult; stdcall;
function getWeatherbyCityName(const theCityName: WideString): ArrayOfString; stdcall;
function getWeatherbyCityNamePro(const theCityName: WideString; const theUserID: WideString): ArrayOfString; stdcall;
end; function GetWeatherWebServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): WeatherWebServiceSoap; implementation function GetWeatherWebServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): WeatherWebServiceSoap;
const
defWSDL = 'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl';
defURL = 'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx';
defSvc = 'WeatherWebService';
defPrt = 'WeatherWebServiceSoap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
RIO.HTTPWebNode.UseUTF8InHeader:= True; //这里加上这一句
try
Result := (RIO as WeatherWebServiceSoap);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end; initialization
InvRegistry.RegisterInterface(TypeInfo(WeatherWebServiceSoap), 'http://WebXml.com.cn/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(WeatherWebServiceSoap), 'http://WebXml.com.cn/%operationName%');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfString), 'http://WebXml.com.cn/', 'ArrayOfString');
RemClassRegistry.RegisterXSClass(getSupportDataSetResult, 'http://WebXml.com.cn/', 'getSupportDataSetResult');
InvRegistry.RegisterInvokeOptions(TypeInfo(WeatherWebServiceSoap), ioDocument);//这里加上这一句 end.

自动生成的WebService文件

 unit Unit1;

 interface

 uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;//, InvokeRegistry, Rio, SOAPHTTPClient; type
TForm1 = class(TForm)
mmo1: TMemo;
pnl1: TPanel;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
//网页例子 http://blog.csdn.net/gjtao1130/article/details/12193235
uses WeatherWebService; procedure TForm1.btn1Click(Sender: TObject);
var
i: Integer;
TMP_Weather: ArrayOfString;
begin
//http://developer.51cto.com/art/200908/147125.htm
//http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
{TMP_Weather := (htpr1 as WeatherWebServiceSoap).getSupportCity('广西');//玉林 (59453)
mmo1.Lines.Clear;
for i := 0 to 10 do
begin
mmo1.Lines.Add(TMP_Weather[i]);
end; }
//TMP_Weather := (htpr1 as WeatherWebServiceSoap).getWeatherbyCityName('59453'); //深圳
TMP_Weather := GetWeatherWebServiceSoap(False,'',nil).getWeatherbyCityName('');
//GetWeatherWebServiceSoap(Self).getWeatherbyCityName('59453'); //玉林 (59453)
mmo1.Lines.Clear;
for i := to do
begin
mmo1.Lines.Add(TMP_Weather[i]);
end;
end; end.

窗体单元文件

 object Form1: TForm1
Left =
Top =
Width =
Height =
Caption = '天气预报WebService'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch =
TextHeight =
object mmo1: TMemo
Left =
Top =
Width =
Height =
Align = alClient
Color = clMoneyGreen
ImeName = '中文 (简体) - 搜狗拼音输入法'
ScrollBars = ssVertical
TabOrder =
end
object pnl1: TPanel
Left =
Top =
Width =
Height =
Align = alTop
Color = clGradientActiveCaption
TabOrder =
object btn1: TButton
Left =
Top =
Width =
Height =
Caption = '测试天气信息'
TabOrder =
OnClick = btn1Click
end
end
end

窗体文件

Delphi7 客户端调用WebService(天气预报)的更多相关文章

  1. 用JDK自带的工具生成客户端调用Webservice的代码

    JAVA下客户端调用Webservice代码简直是让人心生畏惧,今日尝试,做记录如下,参考网上的众多解决方案,下面这种方式是比较简单的. 在jdk的bin目录下有一个wsimport.exe的工具,使 ...

  2. axis1客户端调用webservice的通用代码

    1.axis1 作为web service 客户端时,调用web service 服务端的通用代码 String url = "http://www.webxml.com.cn/webser ...

  3. WinForm客户端调用 WebService时 如何启用Session

    WinForm客户端调用 WebService时 如何启用Session 摘自: http://www.cnblogs.com/swtseaman/archive/2011/04/18/2020176 ...

  4. C#开发WEBService服务 C++开发客户端调用WEBService服务

    编写WEBService服务端应用程序并部署 http://blog.csdn.net/u011835515/article/details/47615425 编写调用WEBService的C++客户 ...

  5. cxf 和 httpclient 客户端调用 webservice 接口

    一.cxf 生成 webservice 客户端 1.接口路径 http://ws.webxml.com.cn/WebServices/WeatherWS.asmx 2.进入你需要放置 webservi ...

  6. 使用AXIS2客户端调用 WEBSERVICE

    问题 在调用WEBSERVICE时,可以使用wsdl2java生成java代码,调用接口,这种方法在接口固定的情况下是一种不错的选择,如果需要动态调用接口,那么这样就行不通了. 解决办法 1.直接构建 ...

  7. Delphi 客户端调用Webservice 的TClientdataset 报出“http://www.borland.com/namespaces/Types-IAppServerSOAP”

    http://www.borland.com/namespaces/Types-IAppServerSOAP 服务器未能识别 HTTP 头 SOAPAction 的值 (2011-04-25 16:4 ...

  8. java客户端调用webService

    啥也不想说,以前使用的方法突然不行了.各种网搜(记得别忘记到jar包哦:axis.jar) 看代码,第一种方式,也就是以前的方式: 改方式不用表名参数名称 public static String i ...

  9. CXF发布webService服务以及客户端调用

    这篇随笔内容是CXF发布webService服务以及客户端调用的方法 CXF是什么? 开发工作之前需要下载CXF和安装 下载地址:http://cxf.apache.org 安装过程: <1&g ...

随机推荐

  1. jquery this 与javascript的this

    <div class="list"> <table> <thead> <tr> <th width="110&quo ...

  2. chaper3_exerise_UVa455_周期串

    #include<iostream> #include<cstring> #include<stdio.h> using namespace std; ; int ...

  3. python异步爬虫

    本文主要包括以下内容 线程池实现并发爬虫 回调方法实现异步爬虫 协程技术的介绍 一个基于协程的异步编程模型 协程实现异步爬虫 线程池.回调.协程 我们希望通过并发执行来加快爬虫抓取页面的速度.一般的实 ...

  4. hdu 2159 FATE

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159 思路:二维完全背包,状态转移方程为: f[j][l]=max(f[j][l],f[j-b[i]] ...

  5. ViewPager部分源码分析一:加载数据

    onMeasure()调用populate(),完成首次数据初始化. populate()维护ViewPager的page,包括mItems和mAdapter. populate(): if (cur ...

  6. 【C#】 用Route进行URL重写

    在.NET Framework 4中,微软推出了Route机制.这种机制不仅在MVC中大量运用,在WebForm中也可以使用. 和Contex.RewritePath()一样,Route功能也是写在G ...

  7. Algorithms, Part I by Kevin Wayne, Robert Sedgewick

    Welcome to Algorithms, Part I 前言 昨天在突然看到了Coursera上Robert Sedgewick讲的Algorithms,Part II看了一些,甚是爽快,所以又去 ...

  8. 【JAVA多线程中使用的方法】

    一.sleep和wait的区别. 1.wait可以指定时间,也可以不指定. 而sleep必须制定. 2.在同步的时候,对于CPU的执行权和以及锁的处理不同. wait:释放执行权,释放锁. sleep ...

  9. BI 项目管理之生命周期跟踪和任务区域

    DW/BI 系统是复杂的实体,构建这种系统的方法必须有助于简化复杂性.13 个方框显示了构建成功的数据仓库的主要任务区域,以及这些任务之间的主要依赖关系.       在生命周期这一级可以进行多方观察 ...

  10. 攻城狮在路上(叁)Linux(二十二)--- linux磁盘挂载与卸载 mount umount

    挂载就是将文件系统与目录结合的操作.挂载点就是目录,该目录就是进入分区或文件系统的入口. 一.挂载前的注意事项: 1.单一文件系统不应该被重复挂载在不同的挂载点中. 2.单一目录不应该重复挂载多个文件 ...