1

Windows サービスとフォームがあり、通信する必要があります。私が訪れたすべてのサイトは、WCF を指しています。最初にサービスに実装しようとしました。このような:

    protected override void OnStart(string[] args)
    {
        event_log.WriteEntry("TOPIAM_ADM: start");
        timer.Start();
        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
    } 

これは、WCF に関連する唯一の行です。サービスを開始すると、このエラーが発生しました

サービスを開始できません。System.InvalidOperationException: ServiceModel クライアント構成セクションでコントラクト 'ServiceReference1.IService1' を参照する既定のエンドポイント要素が見つかりませんでした。これは、アプリケーションの構成ファイルが見つからなかったか、このコントラクトに一致するエンドポイント要素がクライアント要素に見つからなかったためである可能性があります。System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors (ServiceEndpoint serviceEndpoint、文字列構成名) で System.ServiceModel.ChannelFactory.ApplyConfiguration (文字列構成名、構成構成) で System.ServiceModel.ChannelFactory.ApplyConfiguration (文字列構成名) で System.ServiceModel.ChannelFactory .InitializeEndpoint(String configurationName, EndpointAddress アドレス) で System.1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.ConfigurationEndpointTrait1.System.ServiceModel.ConfigでCreateSimplexFactory()...

何時間も調べましたが、構成ファイルを正しく取得する方法についてはまだ手がかりがありません。

WCF には独自のプロジェクトがあり、サービスには別のプロジェクトがあり、その Windows フォーム アプリには別のプロジェクトがあります。構成ファイルからのものであると確信しています。誰でも私を助けることができますか?

サービス プロジェクトの構成:

>     <?xml version="1.0" encoding="utf-8" ?> <configuration>
>   <system.web>
>     <compilation debug="true" />   </system.web>   <!-- When deploying the service library project, the content of the config file must be
> added to the host's    app.config file. System.Configuration does not
> support config files for libraries. -->   <system.serviceModel>
>     <bindings>
>       <basicHttpBinding>
>         <binding name="BasicHttpBinding_IService1" />
>       </basicHttpBinding>
>     </bindings>
>     <client>
>       <endpoint address="http://localhost:8733/Design_Time_Addresses/TOPIAM_WCFLibrary/Service1/"
>         binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
>         contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
>     </client>
>     <behaviors>
>       <serviceBehaviors>
>         <behavior>
>           <!-- To avoid disclosing metadata information, 
>           set the value below to false before deployment -->
>           <serviceMetadata httpGetEnabled="True"/>
>           <!-- To receive exception details in faults for debugging purposes, 
>           set the value below to true.  Set to false before deployment 
>           to avoid disclosing exception information -->
>           <serviceDebug includeExceptionDetailInFaults="False" />
>         </behavior>
>       </serviceBehaviors>
>     </behaviors>   </system.serviceModel>
> 
> </configuration>

WCF プロジェクトの構成

>     <?xml version="1.0" encoding="utf-8" ?> <configuration>
>   <system.web>
>     <compilation debug="true" />   </system.web>   <!-- When deploying the service library project, the content of the config file must be
> added to the host's    app.config file. System.Configuration does not
> support config files for libraries. -->   <system.serviceModel>
>     <services>
>       <service name="TOPIAM_WCFLibrary.Service1">
>         <host>
>           <baseAddresses>
>             <add baseAddress = "http://localhost:8733/Design_Time_Addresses/TOPIAM_WCFLibrary/Service1/"
> />
>           </baseAddresses>
>         </host>
>         <!-- Service Endpoints -->
>         <!-- Unless fully qualified, address is relative to base address supplied above -->
>         <endpoint address="" binding="basicHttpBinding" contract="TOPIAM_WCFLibrary.IService1">
>           <!-- 
>               Upon deployment, the following identity element should be removed or replaced to reflect the 
>               identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
>               automatically.
>           -->
>           <identity>
>             <dns value="localhost"/>
>           </identity>
>         </endpoint>
>         <!-- Metadata Endpoints -->
>         <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
>         <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
>         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
>       </service>
>     </services>
>     <behaviors>
>       <serviceBehaviors>
>         <behavior>
>           <!-- To avoid disclosing metadata information, 
>           set the value below to false before deployment -->
>           <serviceMetadata httpGetEnabled="True"/>
>           <!-- To receive exception details in faults for debugging purposes, 
>           set the value below to true.  Set to false before deployment 
>           to avoid disclosing exception information -->
>           <serviceDebug includeExceptionDetailInFaults="False" />
>         </behavior>
>       </serviceBehaviors>
>     </behaviors>   </system.serviceModel>
> 
> </configuration>

誰が私がどこを間違っているかを指摘できますか?

4

1 に答える 1

0

サービス設定を含む構成ファイルをスタートアップ WinForms アプリケーション プロジェクトに配置する必要があります。

于 2013-08-01T11:35:37.393 に答える