簡體   English   中英

WCF System.InvalidOperationException

[英]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,另一個是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配置文件放在應用程序配置文件中,還是上面的配置有什么問題^?

解決問題的最簡單方法是使用WCF配置編輯器 (Visual Studio附帶)來添加端點。 只需定義端點並與您的配置進行比較即可。

這樣,您就不必通過尋找拼寫問題或放置錯誤的定義來動腦子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM