您的位置:首页 > 编程语言 > Delphi

Delphi编写的webservice和windows 2003的兼容问题

2009-07-09 10:20 453 查看
Delphi编写的webservice和windows 2003的兼容问题
近日在delphi中写了个webservice的服务端程序,本机调试通过的,但是部署到windows 2003的时候出了问题。

首先是windows 2003安装时没带IIS,结果下了个IIS6.0,不想配置和xp下的配置不一样了,如果没有配web扩展服务根本就访问不到那个webservice。

琢磨了半天,才能够访问exe了,结果又出了个500错,说是访问ntdll.dll时有个空指针错误。比较了下,发现确实xp和2003的这个dll文件不同,但是copy不了,因为windows2003在检测到这个文件变了之后马上就覆盖回来了。

到网上找了半天,终于在一篇博客中找到原因,原来是delphi的内核中有个bug,需要修改。附上该博客原文。

Delphi ISAPI and Windows 2003 compatiblity
I had a perfetly OK ISAPI on my Windows 2000 Server. Spending months to

write and debug it has made it a smoothly working peace of work. Then

suddenly we decided to test it on a Windows 2003 Server. As you'd

expect, when Microsoft changes a piece of its operating system, it

shouldn't surprise you if you end up recompiling your Delphi projects.

For the start, I tryied just to copy the ISAPI to the new machine and

see if it works. It didn't. It couldn't find the damn thing and was

giving me 404 Page Not Found error and many other stupid errors. So here

is how I solved it:

First of all, you need to "introduce" your code (ISAPI or CGI) to the

new IIS 6. In order to do this, go to IIS MMC and "allow" your DLL (or

CGI exe) in Web Service Management branch of the left panel tree.

Now try to run your ISAPI. It might work depending on the instructions

you have used in your code. If it gives you something like
Server Error 500
Exception: EAccessViolation
Message: Access violation at address 77F4831D in module 'ntdll.dll'.
Write of address 0040476D

Then you need to fix a bug in Delphi kernel. Open SysUtils.pas

(delphi/Source/Rtl/Sys) and replace the GetEnvironmentVariable function

with the following:

function GetEnvironmentVariable(const Name: string): string;
var
Len: integer;
W : String;
begin
Result := '';
SetLength(W,1);
Len := GetEnvironmentVariable(PChar(Name), PChar(W), 1);
if Len > 0 then
begin
SetLength(Result, Len - 1);
GetEnvironmentVariable(PChar(Name), PChar(Result), Len);
end;
end;

Recompile your ISAPI and it should work now. Remember to make sure this

new SysUtil.pas file gets compiled. You might need to delete its DCU

file from Bin or other folders or add its folder to Delphi search path

in order to force delphi to compile it again.

I have found this solution somewhere in a newsgroup, but I can't find it

again to give "JP" his/her credit
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: