我想從oracle的預存程序透過一個外部dll(delphi編寫)去存取c#寫的webservice時,出現了“尚未呼叫coinitialize”
不知道是怎麼回事,望各位指點一二。
1.我在oracle寫了一個函數addnumber如下:
create or replace function my.add (a in binary_integer,b
in binary_integer) return binary_integer as
external library my_lib
name addnumber
language c;
2.寫了一個流程addtest如下:
create or replace procedure my.addtest (a in
binary_integer,b in binary_integer)
as
retval binary_integer;
begin
retval:=add(a,b);
end;
3.創建了my_lib包:
create or replace library my_lib as 'c:/oracle/ora92/bin/mywebservice.dll';
4.在delphi裡創建了一個mywebservice.dll,並拷貝其到$oracle_home$/bin目錄下,其中有一個方法:
interface
function addnumber(a:integer;b:integer):integer;cdecl;
....
implementation
procedure dogetwebserviceerr(errmsg:string);
var
logfile: textfile;
i:integer;
begin
assignfile(logfile,'d:/test.txt');
try
rewrite(logfile);
write(logfile,errmsg);
finally
closefile(logfile);
end;
end;
function addnumber(a:integer;b:integer):integer;
begin
try
result := getmywebservicesoap().addnumber(a,b);
except
on e: exception do dogetwebserviceerr(eemessage);
else
result :=-1;
end;
end;
.....
其中:getmywebservicesoap()是我用wsdl importer導入產生的mywebservice.pas中的一個方法。
我在該dll的專案文件裡導出了該方法:
exports
addnumber;
5.用c#在localhost建立了一個名為mywebservice的web service,其中有一個名為addnumber的web方法,其定義如下:
[webmethod]
public int addnumber(int a,int b)
{
return a+b;
}
6.我用c#寫了一個windows form客戶端,透過呼叫上面用delphi 寫的dll,測試該web方法,測試成功
[dllimport(dllpath,entrypoint = mywebservice.dll, charset = charset.auto, callingconvention = callingconvention.stdcall)]
private extern static int addnumber(int a,int b);
.....
///測試按鈕
private void buttontestwebservice_click(object sender, system.eventargs e)
{
consle.write( addnumber(1,2));
}
7.在sql*plus裡測試失敗,打開test.txt檔案內容為“尚未呼叫coinitialize”,測試程式碼如下
execute addtest(1,1);
如果將delphi中的addnumber 修改為
function addnumber(a:integer;b:integer):integer;
begin
try
result :=a+b;//不呼叫webservice,直接計算
except
on e: exception do dogetwebserviceerr(eemessage);
else
result :=-1;
end;
end;
執行則成功。
oracle的listener.ora和tnsnames.ora的配置如下
# listener.ora network configuration file: c:/oracle/ora92/network/admin/listener.ora
# generated by oracle configuration tools.
my_extproc_listener =
(address_list =
(address= (protocol=ipc)
(key = extproc)
)
)
sid_list_my_extproc_listener =
(sid_list =
(sid_desc =
(sid_name = extproc)
(oracle_home = c:/oracle/ora92)
(program= c:/oracle/ora92/bin/extproc)
(envs=extproc_dlls=any)
)
)
# tnsnames.ora network configuration file: c:/oracle/ora92/network/admin/tnsnames.ora
# generated by oracle configuration tools.
extproc_connection_data.world =
(description =
(address = (protocol = ipc)(key = extproc))
(connect_data =
(sid = extproc)
)
)