【发布时间】:2021-10-29 08:54:40
【问题描述】:
我成功在 CodeGear Delphi 中为 .NET 2007/2009 创建了 WCF Web 服务。
在本文中,他们创建了控制台应用程序并在其中测试了 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,在我自己的机器上