关于网友提出的“ 请问如何在DLL之中呼叫Webservice?”问题疑问,本网通过在网上对“ 请问如何在DLL之中呼叫Webservice?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 请问如何在DLL之中呼叫Webservice?
描述: 我写一只dll程序要去呼叫C#写的webservice
MyDll.dll
function CallWebService(p01,p02:pointer):bool;stdcall;
var
HH: THTTPRIO;
p1,p2:PString;
tmpstr:string;
begin
if p01=nil then
Exit;
HH:=THTTPRIO.Create(nil);
HH.WSDLLocation:='http://localhost:9898/Helloweb/TestService.asmx?WSDL';
HH.Service:='HelloService';
HH.Port:='HelloServiceSoap';
p1:=PString(p01);
p2:=PString(p02);
tmpstr:=(HH as HelloServiceSoap).HelloWorld;
p2^:=tmpstr;
Result:=true;
end;
之后在程序之中呼叫这个dll function
01 procedure TForm1.Button6Click(Sender: TObject);
02 var
03 pstr1,pstr2:string;
04 pn:PString;
05 s:string;
06 ts:TStringList;
07 begin
08 pstr1:=Edit5.Text;
09 if CallWebService(@pstr1,@pstr2) then begin
10 s:=PString(@pstr2)^;
11 ts:=TStringList.Create;
12 ts.Add(s);
13 Memo1.Text:=s;
14 end;
15 end;
可是这个程序执行到CallWebService函数时会出现”CoInitialize尚未被呼叫”的错误, 请问在dll之中要如何去调用Webservice呢?
解决方案1: use activex
try
CoInitialize(nil);
///////////////////
finally
CoUninitialize;
end;
以上介绍了“ 请问如何在DLL之中呼叫Webservice?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3677552.html