我有一个托管在 Windows 服务中的 WCF 服务库。这两个项目都使用 .NET Framework 4.5。我已将 WCF 服务配置复制到 Windows 服务“app.config”中。作为参考,Windows 服务项目中的配置如下所示:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <connectionStrings>
<add name="SmartDataExchangerContext" connectionString="Data Source=(local)\SQLExpress; Initial Catalog=SmartDataExchanger; Integrated Security=True;" providerName="System.Data.SqlClient" /> </connectionStrings> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel>
<services>
<service name="SmartDataExchangerService.SchoolService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/SmartDataExchangerService/SchoolService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="SmartDataExchangerService.ISchoolService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="127.0.0.1" />
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="SmartDataExchangerService.UserService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/SmartDataExchangerService/UserService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="SmartDataExchangerService.IUserService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors> </system.serviceModel> </configuration>
我正在使用以下命令在开发机器上安装服务:
- “InstallUtil.exe” “C:\Test\MyServiceHost.exe”</li>
该服务已成功安装。我也可以在开发机器上使用 WCF 服务。所以一切都在开发机器上按预期工作。
现在我正在尝试在 Windows Server 2008 R2 机器上安装这个 Windows 服务。我正在执行以下步骤:
- 将 Windows 服务项目的“Dubug”文件夹内容从开发机器复制到服务器。
- 在管理员模式下打开命令提示符。
- 运行命令:
“InstallUtil.exe” “C:\Test\MyServiceHost.exe”</p>
执行上述命令时返回以下错误:
初始化安装时发生异常:System.ArgumentException:URL 上的目录无效。
到目前为止,我做了以下尝试:
- 按照内联注释中的建议从配置文件中删除了元素。
- 将启动对象更改为 ServiceName.Program。
- 我没有使用本地主机,而是尝试使用机器公共 IP 地址。
- 检查我的 WCF 服务没有使用本地驱动器中的任何文件,即没有使用“C:\”或“D:\”。
有人可以建议我应该尝试解决此问题的任何步骤。
更新:
问题解决了。我重新启动了电脑,重新执行了这些步骤,它得到了解决。我怀疑我在执行命令时没有给出正确的路径(我很傻)。