Oralce 调用Delphi写DLL去访问C# WebService的问题
2024-07-21 02:30:06
供稿:网友
我想从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(e. e.message);
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(e. e.message);
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)
)
)