【问题标题】:WPF application with WCF client/service Could not find endpoint element带有 WCF 客户端/服务的 WPF 应用程序找不到端点元素
【发布时间】:2012-01-22 10:37:59
【问题描述】:

请稍等,我要布局整个画面。 我有一个 WPF 应用程序 (.exe),当 COM 对象(VB6 宏)调用应用程序方法时,它需要打开并显示一个窗口。我已经使 .exe 解决方案 COM 中的一个托管代码项目可见,并且 VB6 宏成功地调用了该托管代码项目(COM 存根)上的一个方法。

我的 COM 存根接收方法调用并在 WPF exe 上运行 Process.Start 第一次传入命令行参数。我的应用程序按预期启动。我现在需要通过我的 COM 存根从 VB6 宏发送数据,并在连续调用时将数据发送到 WPF exe。我向我的 WPF exe 解决方案添加了一个 WCF 项目,以生成“netNamedPipeBinding”服务。我在 COM 存根中添加了一个 ServiceReference 来与 WPF exe 对话。我已经使用控制台应用程序单独测试了 WCF 服务并且它可以工作。我已经使用与我的测试用例相同的元数据地址构建了 COM 存根 ServiceReference,并且它正常构建了引用。

我的测试驱动程序调用 COM 存根方法并且 WPF 应用程序启动。我对 COM 存根的下一次调用尝试实例化服务客户端,但我得到了可怕的错误: “在 ServiceModel 客户端配置部分中找不到名称为 'internal' 和合同 'SelectedStudentReference.ISelectedStudent' 的端点元素。”

这是我的 WCF 服务项目部分 WPF exe 解决方案中我的 app.config 的内容。

 <system.serviceModel>
   <bindings />
   <client />
   <services>
     <service name="AwardManager.Service.SelectedStudentService">
       <host>
         <baseAddresses>
           <!--<add baseAddress = "http://localhost:8080/SelectedStudent" />-->
           <add baseAddress="net.pipe://localhost/SelectedStudent"   />
         </baseAddresses>
       </host>
       <endpoint
          name="internal"
          address="net.pipe://localhost/"
          binding="netNamedPipeBinding"
          contract="AwardManager.Service.ISelectedStudent"
        />
       <endpoint
         address="mex/pipes"
         binding="mexNamedPipeBinding"
         contract="IMetadataExchange"
       />
     </service>
   </services>
   <behaviors>
     <serviceBehaviors>
       <behavior>
         <serviceMetadata httpGetEnabled="False"/>
         <serviceDebug includeExceptionDetailInFaults="False" />
       </behavior>
     </serviceBehaviors>
   </behaviors>
 </system.serviceModel>

我尝试将其复制到 WPF app.config 中,但没有成功。此服务与控制台应用程序测试驱动程序一起使用。由于这是我第一次使用 WCF,因此我不知道下一步的故障排除步骤。我查看了another Stackflow question,但不知道它是否适用于我的情况。有什么想法吗?

【问题讨论】:

    标签: wpf wcf com


    【解决方案1】:

    它总是你最后看到的地方。我的控制台应用程序测试驱动程序正在调用带有 ServiceReference 的 COM 存根。我在创建 ServiceClient 的调用之前添加了这行代码。

    string dir = System.IO.Directory.GetCurrentDirectory();
    

    这表明客户端正在测试驱动程序目录中创建。我将它从我的 COM 存根复制到测试驱动程序的 app.config 中。现在像冠军一样工作。

    <system.serviceModel>
       <bindings>
          <netNamedPipeBinding>
             <binding name="internal" closeTimeout="00:01:00" openTimeout="00:01:00"
                 receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
                 transferMode="Buffered" transactionProtocol="OleTransactions"
                 hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
                 maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="Transport">
                   <transport protectionLevel="EncryptAndSign" />
                </security>
             </binding>
          </netNamedPipeBinding>
       </bindings>
       <client>
          <endpoint
             address="net.pipe://localhost/"
             binding="netNamedPipeBinding"
             bindingConfiguration="internal"
             contract="SelectedStudentReference.ISelectedStudent"
             name="internal">
             <identity>
                <userPrincipalName value="me@xyz.com" />
             </identity>
          </endpoint>
       </client>
    </system.serviceModel>
    

    【讨论】:

      【解决方案2】:

      这导致了我的解决方案:将服务引用内容移动到“主”app.config 文件,然后它可以被“子”(wpf) 项目找到。

      【讨论】:

        猜你喜欢
        • 2018-07-09
        • 2015-11-02
        • 1970-01-01
        • 1970-01-01
        • 2023-03-24
        • 2012-04-21
        • 1970-01-01
        • 2014-05-29
        • 2017-06-07
        相关资源
        最近更新 更多