简体   繁体   中英

WCF System.InvalidOperationException

I am getting exception with following message:

Service 'ATPhoneControllerWinService.WCFService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

Service: 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>

Client 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>

Files are in different VS2012 projects (one is WPF and other is windows (not WCF) service). I am new in WCF and I don't know what I am missing.

Project Structure:

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

Okay I am not getting exception now solved it with adding endpoints programmatically:

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

Question remains where should I put xml configuration from app config file or what is wrong with the configuration above^?

The easiest way to get it right is to use the WCF configuration editor (comes with visual studio) to add an endpoint. Just define the endpoint and compare the resulting configuration with yours.

This way you do not have to bang your head by looking for spelling issues or misplaced definitions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM