WCF System.InvalidOperationException

时间:2012-09-22 18:58:54

标签: c# wcf

我收到以下消息的异常:

  

服务'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();

问题仍然是我应该从app配置文件中放置xml配置或上面的配置有什么问题?

1 个答案:

答案 0 :(得分:1)

最简单的方法是使用WCF configuration editor(随visual studio一起提供)添加端点。 只需定义端点并将结果配置与您的配置进行比较。

通过寻找拼写问题或错误定义,您无需担心。