Windows服务中托管的WCF服务在服务器上部署时引发异常
我在Windows服务中托管了一个WCF服务库。这两个项目都使用.NETFramework 4.5。我已将WCF服务配置复制到Windows服务“app.config”中。作为参考,windows服务项目中的配置如下所示:Windows服务中托管的WCF服务在服务器上部署时引发异常,wcf,windows-services,.net-4.5,Wcf,Windows Services,.net 4.5,我在Windows服务中托管了一个WCF服务库。这两个项目都使用.NETFramework 4.5。我已将WCF服务配置复制到Windows服务“app.config”中。作为参考,windows服务项目中的配置如下所示: <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFra
<?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>
我正在使用以下命令在开发计算机上安装服务:
- 按照内联中的建议从配置文件中删除了元素 评论李>
- 将启动对象更改为ServiceName.Program
- 我没有使用localhost,而是尝试使用机器公共IP 地址李>
- 已检查我的WCF服务未使用本地驱动器中的任何文件 i、 e.不使用“C:\”或“D:\”
问题解决了。我重新启动电脑,重新执行步骤,问题就解决了。我怀疑我在执行命令时没有给出正确的路径(愚蠢的我)。这是一个安装错误-与WCF无关。服务器上C:\的根目录中是否存在目录“Test”?@Tim-感谢Tim的评论。我重新启动电脑,重新执行步骤,问题就解决了。我怀疑,正如您正确指出的,我在执行命令时没有给出正确的路径。