【问题标题】:How to publish WCF web service (created in CodeGear Delphi for .NET) on IIS?如何在 IIS 上发布 WCF Web 服务(在 CodeGear Delphi for .NET 中创建)?
【发布时间】:2021-10-29 08:54:40
【问题描述】:

我成功在 CodeGear Delphi 中为 .NET 2007/2009 创建了 WCF Web 服务。

我使用本教程: https://community.embarcadero.com/blogs/entry/building-net-35-wcf-restful-web-services-with-delphi-2007-38508

在本文中,他们创建了控制台应用程序并在其中测试了 Web 服务。

但我需要在 IIS 上发布此 WCF Web 服务 - 我该怎么做?

更新:

我尝试制作 dll(不是控制台应用程序),我的工作如下所示:

1) 单位 uServiceIntf.pas

unit uServiceIntf;

interface

uses
  System.ServiceModel,
  System.ServiceModel.Web;

type
  [ServiceContract(Namespace = 'http://localhost:3000/')]
  IService = interface
    [OperationContract]
    [WebGet(UriTemplate='Add?a={x}&b={y}')]
    function Add(x, y: integer): integer;
  end;

implementation

end.

2) 单元uServiceImpl.pas

unit uServiceImpl;

interface

uses
  uServiceIntf;

type
  TService = class(TObject, IService)
  public
    function Add(x, y: integer): integer;
  end;

implementation

{ TService }

function TService.Add(x, y: integer): integer;
begin
  Result := x + y;
end;

end.

3) DelphiRESTBasicSample_Service_dll.dpr

library DelphiRESTBasicSample_Service_dll;

uses
  SysUtils,
  Classes,
  System.Reflection,
  System.Runtime.InteropServices,
  uServiceImpl in 'uServiceImpl.pas',
  uServiceIntf in 'uServiceIntf.pas';

[assembly: AssemblyTitle('')]
[assembly: AssemblyDescription('')]
[assembly: AssemblyConfiguration('')]
[assembly: AssemblyCompany('')]
[assembly: AssemblyProduct('')]
[assembly: AssemblyCopyright('')]
[assembly: AssemblyTrademark('')]
[assembly: AssemblyCulture('')]

[assembly: AssemblyVersion('1.0.*')]

[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile('')]
[assembly: AssemblyKeyName('')]

[assembly: ComVisible(False)]

begin
end.

4) DelphiRESTBasicSample_Service_dll.svc:

<%@ ServiceHost Language="C#" Service="DelphiRESTBasicSample_Service_dll.TService" %>

5) web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      <behaviors>
       <serviceBehaviors>
         <behavior name="returnFaults">
           <serviceDebug includeExceptionDetailInFaults="true" />
           <serviceMetadata httpGetEnabled="true" />
         </behavior>
        </serviceBehaviors>
      </behaviors>
     <services>
        <service behaviorConfiguration="returnFaults" name="DelphiRESTBasicSample_Service_dll.TService">
          <endpoint address="Add" binding="basicHttpBinding" contract="IService">
          </endpoint>
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:3000/DelphiRESTBasicSample_Service_dll.svc"/>
            </baseAddresses>
          </host>
        </service>
      </services>
    </system.serviceModel>
    <system.web>
      <customErrors mode="Off" />
    </system.web>
    <system.webServer>
        <directoryBrowse enabled="false" />
    </system.webServer>
</configuration>

6) 在 IIS 上发布:

我将 svc 文件和 web.config 文件放在文件夹 D:\MySite 中,将 dll 文件放在文件夹 D:\MySite\bin 中。

我为用户 IIS_IUSRS 授予文件夹 D:\MySite 的所有权限。

我做一个网站:

7) 结果: 我在 Chrome 浏览器中试试这个:

a) http://localhost:3000/Add?a=2&b=3

b) http://localhost:3000/DelphiRESTBasicSample_Service_dll.svc/Add?a=2&b=3

两者都不起作用。

我做错了什么?

【问题讨论】:

  • 到目前为止您尝试过什么,什么成功了,您面临的确切障碍是什么?
  • @Lajos Arpad,我已经阅读了这篇文章并按照其中的所有步骤进行操作 - 得到了一个带有 wcf Web 服务的控制台应用程序 - 现在我可以在浏览器中使用这个 Web 服务,如下所示:localhost:8000/Add?a=2&b=3但是我怎样才能在 IIS 上发布呢?
  • Serg,IIS 是在您自己的机器上运行还是在远程服务器上运行?
  • @Lajos Arpad,在我自己的机器上

标签: wcf delphi iis


【解决方案1】:

阅读本页:https://www.ojdevelops.com/2017/10/deploying-web-application-to-local-iis.html

上面说步骤如下:

此外,如果您想要一个与 localhost 无关的特定 URL,则将您希望成为本地主机的 URL 添加到主机,映射到 127.0.0.1。在这种情况下,您还需要在 IIS 中设置主机标头,请参阅:https://docs.revenera.com/isxhelp23/helplibrary/IISHostHeader.htm

【讨论】:

  • 谢谢,但我只有一个 exe 文件 - 控制台应用程序。但是对于 IIS,我需要 3 个文件:dll、svc、web.config - 我如何在 CodeGear Delphi for .NET 中生成这 3 个文件?
  • @SergS 老实说,我不知道。我的回答一般涉及 IIS 托管,但我在 Delphi 方面没有太多经验。尽管如此,我还是尽力提供帮助。也许这个页面有帮助:edn.embarcadero.com/article/36962
  • 这篇文章与我的问题中的文章非常相似 - 我昨天已经找到了 - 而且其中也没有关于 IIS 发布的信息
  • @SergS 对此感到抱歉。我对这个具体问题的了解不比你多。我认为我的答案是正确的,但它错过了一个必要的细节。也许这个链接有帮助:drbob42.com/examines/examinB4.htm ?
  • 我昨天也阅读了这篇文章——它也没有帮助——它是关于 Delphi Prism 的,它与 CodeGear Delphi for .NET 不同
【解决方案2】:

也许您可以先查看the official documentation,它将逐步指导您完成托管服务。

【讨论】:

  • 谢谢,我已按照本文中的步骤进行操作,但没有成功 - 我更正了我的主要答案 - 描述了我的所有工作 - 你能看看吗?
  • 部署时有没有报错信息,确保你的端口没有被占用。
  • 部署时没有错误信息,端口没有被占用。可能 DelphiRESTBasicSample_Service_dll.svc 或 web.config 错了?
猜你喜欢
  • 1970-01-01
  • 2020-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多