gpt4 book ai didi

c# - WCF 系统.InvalidOperationException

转载 作者:太空宇宙 更新时间:2023-11-03 13:54:56 25 4
gpt4 key购买 nike

我收到以下消息的异常:

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.

服务: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>

客户端应用配置:

<?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 configuration editor (带有 visual studio)来添加端点。只需定义端点并将生成的配置与您的配置进行比较。

这样您就不必为寻找拼写问题或放错地方的定义而绞尽脑汁。

关于c# - WCF 系统.InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12546816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com