2012-09-22 26 views
2

我得到异常有以下消息:WCF System.InvalidOperationException

服务 '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和其他的窗口(不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配置从应用程序配置文件或者是什么上面的配置错误^?

+1

只是一个愚蠢的检查:你是否将服务配置添加到项目的app.config *托管*服务(而不是服务代码库)? – Jeroen

+0

你能告诉我我该怎么做? – Joe

+0

Erhmm ...我的意思是“你 - 通过*意外* - 加....”。如果你确实会得到这个错误。如果这没有任何意义,那么如果你展开你的问题的最后一点,那么这可能会帮助我们:你有什么确切的项目结构,以及类/配置在哪里? – Jeroen

回答

1

最简单的方法是使用WCF configuration editor(附带visual studio)来添加端点。 只需定义端点并将结果配置与您的配置进行比较即可。

通过这种方式,您不必通过查找拼写问题或错误放置的定义来敲你的头。

相关问题