Windows服务中托管的WCF服务在服务器上部署时引发异常

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

我在Windows服务中托管了一个WCF服务库。这两个项目都使用.NETFramework 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”
  • 服务正在成功安装。我还能够在开发机器上使用WCF服务。所以一切都在开发机器上按预期工作

    现在我正在尝试在windows Server 2008 R2计算机上安装此windows服务。我将采取以下步骤:

  • 已从复制了Windows服务项目的“Dubug”文件夹内容 将开发计算机安装到服务器上
  • 在管理员模式下打开命令提示符
  • 运行以下命令:
  • InstallUtil.exe“C:\Test\MyServiceHost.exe”

    执行上述命令时,返回以下错误:

    初始化安装时发生异常: System.ArgumentException:URL上的目录无效

    迄今为止,我已作出以下努力:

    • 按照内联中的建议从配置文件中删除了元素 评论
    • 将启动对象更改为ServiceName.Program
    • 我没有使用localhost,而是尝试使用机器公共IP 地址
    • 已检查我的WCF服务未使用本地驱动器中的任何文件 i、 e.不使用“C:\”或“D:\”
    有人能建议我应该采取什么措施来解决这个问题吗

    更新:


    问题解决了。我重新启动电脑,重新执行步骤,问题就解决了。我怀疑我在执行命令时没有给出正确的路径(愚蠢的我)。

    这是一个安装错误-与WCF无关。服务器上C:\的根目录中是否存在目录“Test”?@Tim-感谢Tim的评论。我重新启动电脑,重新执行步骤,问题就解决了。我怀疑,正如您正确指出的,我在执行命令时没有给出正确的路径。