使用服务引用在 WCF 服务(客户端)和 WCF 应用程序(服务器)之间进行通信

发布于 2024-12-28 20:23:58 字数 5759 浏览 2 评论 0原文

我遇到了一个奇怪的问题,我在尝试将 WCF 服务连接到 WCF 应用程序时遇到错误。两个 WCF 组件可以分别与 WCF 测试客户端和 WCF 一起正常工作。我创建的 Winforms 测试工具。

以下是我在 WCF 服务(客户端)中对指向我的 WCF 应用程序(服务器)的服务引用进行的调用。

EventCreationServiceReference.EventCreationServicePortClient _servicereference =
                        new EventCreationServiceReference.EventCreationServicePortClient();

现在我以与测试工具相同的方式进行连接,我认为唯一的区别是测试工具是一个带有服务引用的普通 Winforms 应用程序,而这是一个与带有 WCF 接口的 Winforms 应用程序通信的 WCF 服务。

错误;

Could not find endpoint element with name 'EventCreationApp.IEventCreationServicePort' 
and contract 'EventCreationAppServiceReference.IEventCreationServicePort' in the 
ServiceModel client configuration section. This might be because no configuration file 
was found for your application, or because no endpoint element matching this name could 
be found in the client element.

现在我想知道为什么找不到合同,所以我尝试创建服务引用,明确说明服务引用合同,但我遇到了一个非常类似的错误。

Uri uri = new Uri("net.tcp://172.26.2.11:8525/EventCreationApp");
EndpointAddress endpointAddress = new EndpointAddress(uri);

EventCreationServiceReference.EventCreationServicePortClient _servicereference =
new EventCreationAppServiceReference.EventCreationServicePortClient(
"EventCreationAppServiceReference.IEventCreationServicePort", endpointAddress);

这是我的 WCF 应用程序的 WCF 配置;

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="EventCreationApp.IEventCreationServicePort" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="EventCreationApp.Service1Behavior"
        name="EventCreationApp.EventCreationServicePort">
        <endpoint address="" binding="netTcpBinding" 
                  bindingConfiguration="EventCreationApp.IEventCreationServicePort"
          contract="EventCreationApp.IEventCreationServicePort"
          name="EventCreationApp.IEventCreationServicePort">
          <identity>
            <dns value="172.26.2.11" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://172.26.2.11:8525/EventCreationApp" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="EventCreationApp.Service1Behavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

...以及用于连接到应用程序的 WCF 服务客户端服务参考代码。

<system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="EventCreationApp.IEventCreationServicePort" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                    maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Transport">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://172.26.2.11:8525/EventCreationApp"
                binding="netTcpBinding" bindingConfiguration="EventCreationApp.IEventCreationServicePort"
                contract="EventCreationAppServiceReference.IEventCreationServicePort"
                name="EventCreationApp.IEventCreationServicePort">
                <identity>
                    <dns value="172.26.2.11" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

救命,我完全被难住了。

I've got a curious problem, where I'm trying to connect a WCF service to a WCF application I'm getting errors. Seperately both WCF components work without fault with the WCF Test Client & a Winforms Test Harness I've created.

Here is the call I make within the WCF service (client) to the service reference pointed at my WCF app (server).

EventCreationServiceReference.EventCreationServicePortClient _servicereference =
                        new EventCreationServiceReference.EventCreationServicePortClient();

Now I'm connecting in the same way as the Test Harness does, the only difference I can think is the Test Harness is a plain Winforms Application with service references, whereas this is a WCF Service talking to a Winforms application with a WCF interface.

The Error;

Could not find endpoint element with name 'EventCreationApp.IEventCreationServicePort' 
and contract 'EventCreationAppServiceReference.IEventCreationServicePort' in the 
ServiceModel client configuration section. This might be because no configuration file 
was found for your application, or because no endpoint element matching this name could 
be found in the client element.

Now I was wondering why the contract was not found so I've tried creating the service reference stating the service reference contract explicity, but I was presented with a very similar error.

Uri uri = new Uri("net.tcp://172.26.2.11:8525/EventCreationApp");
EndpointAddress endpointAddress = new EndpointAddress(uri);

EventCreationServiceReference.EventCreationServicePortClient _servicereference =
new EventCreationAppServiceReference.EventCreationServicePortClient(
"EventCreationAppServiceReference.IEventCreationServicePort", endpointAddress);

Here is my WCF configuration for the WCF Application;

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="EventCreationApp.IEventCreationServicePort" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="EventCreationApp.Service1Behavior"
        name="EventCreationApp.EventCreationServicePort">
        <endpoint address="" binding="netTcpBinding" 
                  bindingConfiguration="EventCreationApp.IEventCreationServicePort"
          contract="EventCreationApp.IEventCreationServicePort"
          name="EventCreationApp.IEventCreationServicePort">
          <identity>
            <dns value="172.26.2.11" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://172.26.2.11:8525/EventCreationApp" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="EventCreationApp.Service1Behavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

...and the WCF service client service reference code for connecting to the application.

<system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="EventCreationApp.IEventCreationServicePort" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                    maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Transport">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://172.26.2.11:8525/EventCreationApp"
                binding="netTcpBinding" bindingConfiguration="EventCreationApp.IEventCreationServicePort"
                contract="EventCreationAppServiceReference.IEventCreationServicePort"
                name="EventCreationApp.IEventCreationServicePort">
                <identity>
                    <dns value="172.26.2.11" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

Help, I'm completely stumped.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行至春深 2025-01-04 20:23:58

客户端配置不应该包含“客户端”端点吗?

WCF 客户端配置

[编辑]

您是说 WCF 服务正在与WCF 应用程序。不应该反过来吗?

或者你是说 WCF 服务是客户端,WCF 应用程序是服务?

Shouldn't the client config contain 'Client' end points?

WCF Client Configuration

[Edit]

You are saying that WCF service is talking to WCF application. Shouldn't it be reverse?

Or are you saying WCF Service is the client and WCF application is the service?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文