2

次のメッセージで例外が発生します:

サービス'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プロジェクトにあります(1つはWPFで、もう1つは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構成をどこに置くべきか、または上記の構成の何が問題になっているのかという疑問が残ります^?

4

1 に答える 1

1

これを正しく行う最も簡単な方法は、WCF 構成エディター(Visual Studio に付属) を使用してエンドポイントを追加することです。エンドポイントを定義し、結果の構成を自分のものと比較するだけです。

こうすれば、スペルの問題や間違った定義を探して頭を悩ませる必要がなくなります。

于 2012-09-23T11:35:08.813 に答える