一段时间以前,我一直在考虑如何隐藏web服务的默认页面,即IAppServer和IAppServerSOAP接口,它们是默认显示的。我知道我的Webservice接口有这些接口作为祖先,但我认为在默认页面上“看到”这些接口是没有意义的,因为客户端程序不会直接使用它们。
有没有办法隐藏这些接口,只保留我们的接口和其他创建的接口?
发布于 2012-02-08 12:59:45
我终于明白了!
为此,我所要做的就是编辑WebModule2DefaultHandlerAction方法,即DefaultHandler WebActionItem的OnAction事件处理程序。
最后一个事件处理程序现在如下所示:
procedure TWEBMWebService.WebModule2DefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
Conteudo: String;
begin
WSHPWebService.ServiceInfo(Sender, Request, Response, Handled);
Conteudo := Response.Content;
try
HideInterfaces(Conteudo,['IAppServer','IAppServerSOAP']);
finally
Response.Content := Conteudo;
end;
end;
HideInterfaces过程如下:
procedure HideInterfaces(var aContent: String; aInterfaces: array of string);
var
Intf: String;
i: Integer;
begin
if Length(aInterfaces) = 0 then
Exit;
with TStringList.Create do
try
{ Remove todos os enters }
aContent := StringReplace(aContent,#13#10,' ',[rfreplaceAll]);
{ Separa tudo baseando-se nos TR }
Text := StringReplace(aContent,'<tr>',#13#10'<tr>'#13#10,[rfreplaceAll,rfIgnoreCase]);
Text := StringReplace(Text,'</tr>',#13#10'</tr>'#13#10,[rfreplaceAll,rfIgnoreCase]);
{ Neste ponto, cada linha do StringList contém ou <TR>, ou </TR>, ou o que
houver entre os dois, então circulamos por cada interface que precisa ser
ocultada }
for Intf in aInterfaces do
begin
for i := 0 to Pred(Count) do
if Pos(LowerCase(Intf),LowerCase(Strings[i])) > 0 then
Break;
{ Se achou a interface, oculta a linha inteira de tabela, removendo do
StringList i, i-1 e i+1 }
if i < Count then
begin
Delete(i+1);
Delete(i);
Delete(i-1);
end;
end;
aContent := Text;
finally
Free;
end;
end;
注释是葡萄牙语的,很抱歉,但是代码很容易理解。如果你喜欢并使用它,请让我知道,并给我一些信用,对吧;)
我想要感谢你们所有人的宝贵答案。没有你的帮助,我永远也找不到解决方案!谢谢大家!
发布于 2012-01-02 21:57:25
您应该能够更改服务返回的WSDL。我认为有一个WSDL控件,您可以在其中覆盖WSDL响应以编辑它,或者替换您想要的任何内容。
具体地说,就是向WebModule表单添加一个TWSDLHTMLPublish组件。使用OnBeforePublishingWSDL编写您自己的WSDL,如下所示:
procedure TWebModule2.WSDLHTMLPublish1BeforePublishingWSDL(
const IntfName: WideString; var WSDL: WideString; var Handled: Boolean);
begin
WSDL := '<foo>bar</foo>';
Handled := true;
end;
发布于 2013-06-27 14:12:02
谢谢卡洛斯!
但最终我找到了另一种方法。。。只需取消注册接口即可
InvRegistry.UnRegisterInterface(TypeInfo(IAppServer));
InvRegistry.UnRegisterInterface(TypeInfo(IAppServerSOAP));
InvRegistry.UnRegisterInterface(TypeInfo(IWSDLPublish));
https://stackoverflow.com/questions/8705498
复制