为什么Delphi 6调用C#的WebService,只要调用传入参数是string类型的函数就报错?

Ki1381 2008-04-14 11:35:56
SOAP Response Packet: result element expected, received "<ConfrimResponse xmlns="http://tempuri.org/"/>"

WebService应该没问题,用C#调完全正常,而且用Delphi调,不需要string参数的函数都没问题,返回类型是string也没问题。

D6是古董了点,但暂时不能动,请高手们提供个解决方法。
...全文
469 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
pal2003 2011-12-03
  • 打赏
  • 举报
回复
InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap), ioDocument);
qiuqiu505 2011-08-08
  • 打赏
  • 举报
回复
这个问题楼主是怎么解决的?
mantti 2008-04-23
  • 打赏
  • 举报
回复
在function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''): ServiceSoap;中,最好加上HTTPRIO,即
function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ServiceSoap;
以前用的时候总感觉动态创建HTTPRIO会有问题,所以最好能在窗体上放一个HTTPRIO,调用的时候带过去


function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ServiceSoap;
var
RIO: THTTPRIO;
defWSDL, defURL, defSvc, defPrt: string;
begin
CoInitialize(nil);
if HTTPRIO <> nil then
begin
With HTTPRIO do
begin
defWSDL = 'http://10.16.66.16/KiTest/service.asmx?wsdl';
defURL = 'http://10.16.66.16/KiTest/service.asmx';
defSvc = 'Service';
defPrt = 'ServiceSoap';
end;
end;

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;
try
Result := (RIO as IWebServiceAPI);
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;
CoUnInitialize;
end;

Ki1381 2008-04-20
  • 打赏
  • 举报
回复
以下是自动生成的最原始的代码:
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://10.16.66.16/KiTest/service.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2008-04-09 13:00:12 - $Revision: 1.9.1.0.1.0.1.9 $)
// ************************************************************************ //
unit service;
interface
uses InvokeRegistry, 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"
// !:int - "http://www.w3.org/2001/XMLSchema"
// !:string - "http://tempuri.org/"
ArrayOfString = array of String; { "http://tempuri.org/" }
// ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: http://tempuri.org/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : ServiceSoap
// service : Service
// port : ServiceSoap
// URL : http://10.16.66.16/KiTest/service.asmx
// ************************************************************************ //
ServiceSoap = interface(IInvokable)
['{77573149-9C57-FA51-F11F-EFD527C91BD9}']
function HelloWorld: String; stdcall;
function GetBarCode(const index: Integer; const data: ArrayOfString): String; stdcall;
function Confirm(const s: string): string; stdcall;
end;
function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''): ServiceSoap;

implementation
uses SOAPHTTPClient;
function GetServiceSoap(UseWSDL: Boolean; Addr: string): ServiceSoap;
const
defWSDL = 'http://10.16.66.16/KiTest/service.asmx?wsdl';
defURL = 'http://10.16.66.16/KiTest/service.asmx';
defSvc = 'Service';
defPrt = 'ServiceSoap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
RIO := THTTPRIO.Create(nil);
try
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
Result := (RIO as ServiceSoap);
finally
if Result = nil then
RIO.Free;
end;
end;

initialization
InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'http://tempuri.org/%operationName%');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfString), 'http://tempuri.org/', 'ArrayOfString');
end.


以下为调用代码
procedure TForm1.Button1Click(Sender: TObject);
var
saa:ServiceSoap;
str:string;
begin
str := 'abc';
saa := GetServiceSoap();
edit1.text := saa.Confirm(str);
end;


谢谢!
CCC的 2008-04-16
  • 打赏
  • 举报
回复
要看你接口单元中confirm里面生成的是什么类型的了,最好把代码贴出来看看
dl110 2008-04-16
  • 打赏
  • 举报
回复
好像没那么复杂,这是我的应用:
//以下是Delphi生成的WebService调用
unit version;

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"



// ************************************************************************ //
// Namespace : http://csyangpeng.cn/
// soapAction: http://csyangpeng.cn/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : VersionSoap
// service : Version
// port : VersionSoap
// URL : http://www.MyService.com/services/version.asmx
// ************************************************************************ //
VersionSoap = interface(IInvokable)
['{B274BBBB-F68D-7338-454D-6E33B840DEBE}']
function GetDataURL: WideString; stdcall;
function GetSSJKURL: WideString; stdcall;
function GetVersion: WideString; stdcall;
function GetDataVersion: WideString; stdcall;
procedure SetDataVersion; stdcall;
end;

function GetVersionSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): VersionSoap;


implementation

uses UniMain;

function GetVersionSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): VersionSoap;
const
defSvc = 'Version';
defPrt = 'VersionSoap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
//Addr := defWSDL
Addr := MainForm.edtWebService.Text+'?wsdl'
else
//Addr := defURL;
Addr := MainForm.edtWebService.Text;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as VersionSoap);
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(VersionSoap), 'http://csyangpeng.cn/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(VersionSoap), 'http://csyangpeng.cn/%operationName%');

end.

在主程序中引用:uses version;
然后:
    Label11.Caption:= '当前版本号:'+GetVersionSoap.GetDataVersion;
就OK了。
Ki1381 2008-04-16
  • 打赏
  • 举报
回复
谢谢楼上各位,可是还是不行

procedure TForm1.Button1Click(Sender: TObject);
var
saa:ServiceSoap;
str:widestring;
begin
str := widestring('abc');
saa := GetServiceSoap();
edit1.Text := saa.Confirm(str);
end;

这样写对吗?
  • 打赏
  • 举报
回复
估计是字符集的问题吧,用utf-8试试看
喝口水 2008-04-15
  • 打赏
  • 举报
回复
PChar类型可以,
String是第一位是字符串的长度,从第二位开始才是真正的数据
luxuewei5214 2008-04-15
  • 打赏
  • 举报
回复
转为Pchar类型传入试试
myvicy 2008-04-15
  • 打赏
  • 举报
回复
两种数据类型不一样要转换一下.
mantti 2008-04-15
  • 打赏
  • 举报
回复
用WideString
dl110 2008-04-14
  • 打赏
  • 举报
回复
好像WebService返回的都是WideString。但这两个类型是否可强制转换,不知道了。
本项目提供了一套基于Python与OpenCV技术实现的手写体练习册图像自动生成系统,可作为计算机相关专业学生的课程实践课题、学期综合任务或工程实训案例。该方案在学术评审环节获得了接近满分的优异评价,具体技术实现包含以下核心模块: 系统采用分层架构设计,首先通过随机参数生成器创建差异化的页面布局模板,包括行间距波动、页边距随机偏移及文本区域动态划分。在笔迹模拟层面,程序整合了多种手写字体库,并引入墨水扩散模拟算法与书写压力变化模型,使生成的文字呈现自然书写的不规则特性。 针对作业本背景合成,系统实现了网格线矢量绘制引擎,支持线宽抖动、颜色渐变及纸张纹理叠加。同时加入基于概率模型的页面折痕生成器与光照不均匀模拟器,进一步提升图像的真实感。输出模块提供多分辨率适配功能,可批量生成适用于不同应用场景的练习册样本。 本方案已通过教育领域专家的多维度评估,在算法创新性、工程完备性及实用价值方面均获得高度认可,特别适合作为计算机视觉入门到进阶的过渡实践项目。所有代码均采用模块化封装,配备完整的参数配置接口与可视化调试工具。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
内容概要:本文档围绕“并_离网风光互补制氢合成氨【复现】并_离网风光互补制氢合成氨系统容量-调度优化分析【Cplex求解】(Matlab代码实现)系统容量-调度优化分析”的Matlab代码实现展开,重点介绍基于Cplex求解器对该系统进行容量配置与调度优化的技术路径。该研究融合风能、太阳能等可再生能源,通过电解水制氢并进一步合成氨,构建绿色能源转化链条,并分别针对并网与离网两种运行模式开展优化建模。文档提供了完整的Matlab代码实现方案,涵盖目标函数设定、约束条件构建、变量定义及Cplex调用流程,旨在实现系统经济性、稳定性和可持续性的综合最优。同时,文中提及多个相关研究方向,如虚拟电厂多时间尺度调度、储能优化、风光预测误差处理等,展示了该领域广泛的科研应用场景和技术延展性。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及工程技术人员,尤其适合从事新能源系统规划、综合能源系统优化、氢能利用等相关领域的研究人员。; 使用场景及目标:①掌握风光互补制氢合成氨系统的建模方法与优化思路;②学习如何使用Matlab结合YALMIP工具箱调用Cplex求解器解决混合整数线性规划问题;③应用于科研项目复现、论文写作支撑或实际工程项目前期仿真分析;④拓展至虚拟电厂、微网调度、碳交易机制下的能源系统优化等关联领域研究。; 阅读建议:建议读者结合文档中提供的网盘资源下载完整代码与案例数据,按照目录顺序逐步学习,重点关注模型构建逻辑与代码实现细节之间的对应关系。在复现过程中应深入理解约束条件的物理意义,并尝试调整参数或扩展模型结构以增强实战能力。同时,可将本案例作为模板迁移至其他能源系统优化问题中,提升科研效率与创新能力。
内容概要:本文围绕“考虑阶梯式碳交易机制与电制氢的综合能源系统热电优化”展开,通过Matlab代码实现对综合能源系统的热电联合优化调度进行建模与仿真。研究引入阶梯式碳交易机制,以激励低碳运行,并结合电解水制氢技术提升系统对可再生能源的消纳能力,增强能源系统的灵活考虑阶梯式碳交易机制与电制氢的综合能源系统热电优化(Matlab代码实现)性与环保性。文中构建了包含电、热、氢等多种能量形式耦合的优化模型,综合考虑设备运行约束、能量平衡、碳排放成本等因素,旨在降低系统运行总成本并减少碳排放。; 适合人群:具备一定电力系统、能源系统背景知识,熟悉Matlab编程与优化建模的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于综合能源系统(IES)的多能协同优化调度研究;②适用于含可再生能源接入、氢能存储与碳交易机制的低碳能源系统建模与仿真;③为实现“双碳”目标下的能源系统转型提供技术路径与量化分析工具。; 阅读建议:建议读者结合Matlab代码与文档内容同步学习,重点关注目标函数构建、约束条件设置及阶梯式碳交易机制的数学表达,可通过修改参数进行敏感性分析,进一步深化对多能系统优化运行机制的理解。

16,742

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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