WCF服务库和服务的正确端点/基址

时间:2018-08-03 23:03:39

标签: c# visual-studio wcf windows-services app-config

我创建了WCF服务库和随附的Windows Service。我知道该代码有效,因为我可以使用WcfTestClient.exe,而且一切都很好。我遇到问题的地方是使用InstallUtil.exe在服务器上安装服务。我得到:

WCF Error

我肯定会启动该服务并参加OnStart事件。我走得更远,因为我看到了OnOpen()调用,所以我确切知道服务中哪条线失败。由于我的测试服务库可以正常工作,因此我认为问题出在App.config文件上,但是...

:: From WcfServiceLibrary1
<system.serviceModel>
    <services>
      <service name="WcfServiceLibrary1.CRUDContact">
        <endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.ICRUDContact">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:9000/WcfServiceLibrary1/CRUDContact/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
</system.serviceModel>

:: From WindowsService1
<system.serviceModel>
    <services>
        <service name="WcfServiceLibrary1.CRUDContact">
            <endpoint address="uri" binding="wsHttpBinding" contract="WcfServiceLibrary1.ICRUDContact">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:9000/WindowsService1/Service1/" />
                </baseAddresses>
            </host>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
                <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

这是显示解决方案中项目的屏幕截图。一幅图片值得一千个单词。

WCF Service Library and Windows Service

就参考文献而言:

  1. WCF Service Library and Windows Service Hosting
  2. Service Has Zero Application (Non-Infrastructure) Endpoints
  3. Newbie Link from SO Question

代码项目文章说要复制app.config文件,而关于SO问题的答案尚不清楚。一个答案说服务中只有app.config,而库中没有。另一个人说没有app.config,而是使用web.config,而不是那个人说的是哪一个以及应如何显示。

我相信Namespace.Interface应该很好,因为Visual Studio不喜欢它,这很多,它显示出弯曲的行并在违规行上发出警告/错误。

可悲的是,新手文章使用TopShelf和NuGet,而我真的想使Windows Service正常工作,所以不要这样做。我确实看到在哪里使用netTcp作为绑定。复制并粘贴了一些修改(不同的名称)后,一切都无法正常工作,因此我不得不返回。

基本上,许多文章都集中在简单的内容上,例如操作合同,而复杂而重要的内容却很少提及。

有想法吗?

0 个答案:

没有答案