When I want to access the webservice written in C# from Oracle's stored procedure through an external dll (written in Delphi), "coinitialize has not been called yet" appears.
I don't know what's going on, I hope you can give me some advice.
1. I wrote a function addnumber in Oracle as follows:
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. Wrote a process addtest as follows:
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. Created the my_lib package:
create or replace library my_lib as 'c:/oracle/ora92/bin/mywebservice.dll';
4. Create a mywebservice.dll in Delphi and copy it to the $oracle_home$/bin directory. There is a method:
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;
.....
Among them: getmywebservicesoap() is a method in mywebservice.pas that I imported using wsdl importer.
I exported this method in the project file of the dll:
exports
addnumber;
5. Use C# to create a web service named mywebservice on localhost. There is a web method named addnumber, which is defined as follows:
[webmethod]
public int addnumber(int a,int b)
{
return a+b;
}
6. I wrote a windows form client in c# and tested the web method by calling the dll written in delphi above. The test was successful.
[dllimport(dllpath,entrypoint = mywebservice.dll, charset = charset.auto, callingconvention = callingconvention.stdcall)]
private extern static int addnumber(int a,int b);
...
///Test button
private void buttontestwebservice_click(object sender, system.eventargs e)
{
consle.write( addnumber(1,2));
}
7. The test failed in sql*plus. When the test.txt file was opened, the content was "coinitialize has not been called yet". The test code is as follows
execute addtest(1,1);
If you modify addnumber in delphi to
function addnumber(a:integer;b:integer):integer;
begin
try
result :=a+b;//Do not call webservice, calculate directly
except
on e: exception do dogetwebserviceerr(eemessage);
else
result :=-1;
end;
end;
Execution is successful.
The configurations of oracle's listener.ora and tnsnames.ora are as follows
# 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)
)
)