【问题标题】:Service works from wcfTestClient but fails in Console Application服务从 wcfTestClient 工作,但在控制台应用程序中失败
【发布时间】:2012-09-14 13:11:26
【问题描述】:

我有一个服务。当我使用 wcfTestClient 进行测试时,该服务运行良好。当我从控制台应用程序客户端调用时,它会引发以下错误:

在 ServiceModel 客户端配置部分中找不到引用合同“ICalculationService”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。

服务跟踪:

说明:无法查找通道以接收传入消息。未找到端点或 SOAP 操作。 来源:System.ServiceModel.Activation.HostedHttpTransportManager/28072850

可能的问题是什么?

参考:There was no channel that could accept the message with action


服务配置

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceTypeBehaviors" >
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_CalculationServiceInterface"
        closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
        sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
        hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="CalculationService.CalculationService" behaviorConfiguration="MyServiceTypeBehaviors">
    <endpoint address="CalculationService" behaviorConfiguration=""
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_CalculationServiceInterface"
        contract="ICalculationService" />
  </service>
  </services>
  </system.serviceModel>

客户端配置

   <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_CalculationServiceInterface"
                closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
                sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
                hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="524288" maxStringContentLength="524288" maxArrayLength="524288"
                    maxBytesPerRead="524288" maxNameTableCharCount="524288" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:2724/CalculationService.svc/CalculationService" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_CalculationServiceInterface"
            contract="ICalculationService" name="CalculationServicePort" />
    </client>
    </system.serviceModel>

WSDL

  <definitions xmlns:import0="urn:lijo:demos:multiplyservice:messages:v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import1="urn:lijo:demos:multiplyservice:data:v1" xmlns:tns="urn:lijo:demos:multiplyservice:calculation:v1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="CalculationService" targetNamespace="urn:lijo:demos:multiplyservice:calculation:v1" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />

  <types>
  <xsd:schema>
  <xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantMessages.xsd" namespace="urn:lijo:demos:multiplyservice:messages:v1" />
  <xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantData.xsd" namespace="urn:lijo:demos:multiplyservice:data:v1" />
  </xsd:schema>
  </types>

  <message name="getMultiplied">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <part name="parameters" element="import0:getMultiplied" />
  </message>

  <message name="getMultipliedResponse">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <part name="parameters" element="import0:getMultipliedResponse" />
  </message>

  <portType name="CalculationServiceInterface">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />

  <operation name="getMultiplied">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <input message="tns:getMultiplied" />
  <output message="tns:getMultipliedResponse" />
  </operation>

  </portType>

  <binding name="BasicHttpBinding_CalculationServiceInterface" type="tns:CalculationServiceInterface">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
  <operation name="getMultiplied">
  <soap:operation soapAction="urn:lijo:demos:multiplyservice:calculation:v1:getMultiplied" style="document" />
  <input>
    <soap:body use="literal" />
  </input>
  <output>
    <soap:body use="literal" />
  </output>
  </operation>
  </binding>
  <service name="CalculationServicePort">
  <port name="CalculationServicePort" binding="tns:BasicHttpBinding_CalculationServiceInterface">
  <soap:address location="http://localhost/CalculationService" />
  </port>
  </service>
  </definitions>

XSD 文件:

所需的XSD可以在One WCF service – two clients; One client does not work找到

【问题讨论】:

    标签: c# .net wcf


    【解决方案1】:

    您的问题可能在您的客户端配置中。

    <endpoint address="http://localhost:2724/CalculationService.svc/CalculationService"
    

    您是否已将本地 IIS 配置为在端口 2724 托管服务?

    先仔细检查一下。

    编辑:如果您使用 Visual Studio 进行测试,请see this article 获取有关配置特定端口号的建议。

    【讨论】:

    • 我正在使用 Visual Studio 2010 进行测试;未安装在 IIS 上。
    【解决方案2】:

    让我承认这是我的一个错误。我将客户端配置保存在 output.config 文件中(由 WCSF Blue 工具生成)。当我将它复制到 app.config 时,它运行良好。

    【讨论】:

    • 谢谢,莉乔。我的回答有帮助吗?此外,您应该将某些内容标记为已接受的答案。
    猜你喜欢
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 2018-02-01
    相关资源
    最近更新 更多