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

时间:2012-01-26 11:40:27

标签: wcf wcf-client

我有一个奇怪的问题,我正在尝试将WCF服务连接到WCF应用程序我遇到了错误。单独的两个WCF组件在WCF测试客户端&我创建的Winforms测试工具。

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

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

现在我以与Test Harness相同的方式进行连接,我能想到的唯一区别是Test Harness是一个带有服务引用的简单Winforms应用程序,而这是一个与Winforms应用程序通信的WCF服务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>

帮助,我完全被难过了。

1 个答案:

答案 0 :(得分:0)

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

WCF Client Configuration

[编辑]

您说WCF服务正在与WCF应用程序通信。不应该逆转吗?

或者您是说WCF服务是客户端而WCF应用程序是服务?