我写一只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呢?
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呢?
try
CoInitialize(nil);
///////////////////
finally
CoUninitialize;
end;