2

我收到以下消息的异常:

服务“ATPhoneControllerWinService.WCFService”的应用程序(非基础设施)端点为零。这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在服务元素中没有定义端点。

服务:App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <system.serviceModel>
    <services>
      <service name="ATPhoneControllerWinService.WCFService">
        <endpoint address="net.pipe://localhost/ATPipe" 
                  binding="netNamedPipeBinding"
                  contract="ATPhoneControllerWinService.IWCFService" 
        />
      </service>
    </services>
  </system.serviceModel>
</configuration>

客户端 App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <system.serviceModel>
    <client>
      <endpoint
         address  = "net.pipe://localhost/ATPipe"
         binding  = "netNamedPipeBinding"
         contract = "ATPhoneControllerWinService.IWCFService"
         />
    </client>
  </system.serviceModel>
</configuration>

文件位于不同的 VS2012 项目中(一个是 WPF,另一个是 windows(不是 WCF)服务)。我是 WCF 的新手,我不知道我错过了什么。

项目结构:

C:.
|   ATPhoneController.sln
|   tree.txt
|   
+---ATPhoneController
|   |   App.config <<<---<b>This is second App.config listed above</b>
|   |   App.xaml
|   |   App.xaml.cs
|   |   ATPhoneControllerUI.csproj
|   |   MainWindow.xaml
|   |   MainWindow.xaml.cs
|   |   
|   +---bin
|   |   +---Debug
|   |   |       App.config
|   |   |       ATPhoneController.exe
|   |   |       ATPhoneController.exe.config
|   |   |       ATPhoneController.pdb
|   |   |       ATPhoneController.vshost.exe
|   |   |       ATPhoneController.vshost.exe.config
|   |   |       ATPhoneControllerWinService.exe
|   |   |       ATPhoneControllerWinService.pdb
|   |   |       
|   |   \---Release
|   +---obj
|   |   \---Debug
|   |       |   App.g.cs
|   |       |   App.g.i.cs
|   |       |   ATPhoneController.csproj.FileListAbsolute.txt
|   |       |   ATPhoneController.csproj.GenerateResource.Cache
|   |       |   ATPhoneController.csprojResolveAssemblyReference.cache
|   |       |   ATPhoneController.exe
|   |       |   ATPhoneController.g.resources
|   |       |   ATPhoneController.pdb
|   |       |   ATPhoneController.Properties.Resources.resources
|   |       |   ATPhoneControllerUI.csproj.FileListAbsolute.txt
|   |       |   ATPhoneControllerUI.csproj.GenerateResource.Cache
|   |       |   ATPhoneControllerUI.csprojResolveAssemblyReference.cache
|   |       |   ATPhoneController_MarkupCompile.cache
|   |       |   ATPhoneController_MarkupCompile.i.cache
|   |       |   DesignTimeResolveAssemblyReferencesInput.cache
|   |       |   MainWindow.baml
|   |       |   MainWindow.g.cs
|   |       |   MainWindow.g.i.cs
|   |       |   TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
|   |       |   TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
|   |       |   
|   |       \---TempPE
|   |               Properties.Resources.Designer.cs.dll
|   |               
|   +---Properties
|   |       AssemblyInfo.cs
|   |       Resources.Designer.cs
|   |       Resources.resx
|   |       Settings.Designer.cs
|   |       Settings.settings
|   |       
|   \---Service References
\---ATPhoneControllerWinService
    |   App.config <<<---<b>This is first App.config listed above</b>
    |   ATPhoneControllerWinService.csproj
    |   ATPhoneControllerWinService.csproj.user
    |   ATWinService.cs
    |   IWCFService.cs
    |   WCFService.cs
    |   WinServiceInstaller.cs
    |   
    +---bin
    |   +---Debug
    |   |       App.config
    |   |       ATPhoneControllerWinService.exe
    |   |       ATPhoneControllerWinService.exe.config
    |   |       ATPhoneControllerWinService.InstallLog
    |   |       ATPhoneControllerWinService.pdb
    |   |       ATPhoneControllerWinService.vshost.exe
    |   |       ATPhoneControllerWinService.vshost.exe.config
    |   |       ATPhoneControllerWinService.vshost.exe.manifest
    |   |       InstallUtil.InstallLog
    |   |       
    |   \---Release
    +---obj
    |   \---Debug
    |       |   ATPhoneControllerWinService.csproj.FileListAbsolute.txt
    |       |   ATPhoneControllerWinService.exe
    |       |   ATPhoneControllerWinService.pdb
    |       |   DesignTimeResolveAssemblyReferences.cache
    |       |   DesignTimeResolveAssemblyReferencesInput.cache
    |       |   TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
    |       |   TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
    |       |   
    |       \---TempPE
    +---Properties
    |       AssemblyInfo.cs
    |       
    \---Service References

好的,我现在没有遇到异常,通过以编程方式添加端点来解决它:

host = new ServiceHost(typeof(WCFService), new Uri("net.pipe://localhost/ATPipe"));
            host.AddServiceEndpoint(typeof(IWCFService), new NetNamedPipeBinding(), "net.pipe://localhost/ATPipe");
            host.Open();

问题仍然存在,我应该将应用程序配置文件中的 xml 配置放在哪里,或者上面的配置有什么问题^?

4

1 回答 1

1

最简单的方法是使用WCF 配置编辑器(Visual Studio 附带)来添加端点。只需定义端点并将生成的配置与您的配置进行比较。

这样,您就不必寻找拼写问题或放错位置的定义。

于 2012-09-23T11:35:08.813 回答