【问题标题】:Calling webservice from WCF service从 WCF 服务调用 web 服务
【发布时间】:2009-10-01 10:55:21
【问题描述】:

我在使用 WCF 服务中的 Web 服务 (c#.net) 时遇到问题。 我得到的错误是 EndPointNotFoundException “TCP 错误代码 10061:无法建立连接,因为目标机器主动拒绝它”

我编写了一个单元测试来检查我是否可以向 Web 服务发送请求并且它工作正常 [单元测试使用与我的 WCF 服务相同的绑定配置]

Web 服务和 WCF 服务(客户端)具有基本的 http 绑定。

是否有人遇到过从 WCF 服务调用 Web 服务的类似问题?

服务模型部分如下

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="DataService" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05: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>
    <client>
        <endpoint address="http://10.22.33.67/Service/DataService.asmx" binding="basicHttpBinding" 
            bindingConfiguration="DataService" contract="Service.DataService" name="DataService"/>
    </client>
    <services>
        <service name="TestToConsumeDataService.WCFHost.Service1" behaviorConfiguration="TestToConsumeDataService.WCFHost.Service1Behavior">
            <!-- Service Endpoints -->
            <endpoint address="" binding="basicHttpBinding" contract="TestToConsumeDataService.WCFHost.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>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="TestToConsumeDataService.WCFHost.Service1Behavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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>

单元测试项目也使用相同的服务模型部分并且可以正常工作。唯一的问题是从另一个 WCF 服务调用该服务时。能否请教一下。

【问题讨论】:

标签: wcf web-services


【解决方案1】:

您提到了“webservice”和“WCF 服务”——所以“webservice”是一种老式的 ASMX Web 服务??

您的 WCF 服务是如何托管的?在 IIS 中?您是否拥有从 web.config 中的 WCF 调用的 web 服务的必要端点信息?

您能否向我们展示您的相关配置,例如请问您的 web.config(或 app.config,如果您是自托管 WCF 服务)的 &lt;system.serviceModel&gt; 部分?

该错误意味着您正在使用的地址上没有网络服务正在侦听,或者您没有访问权限。您是否缺少一些安全措施或其他什么?

马克

【讨论】:

  • 嗨,我认为这与安全有关。 nunits 工作正常,因为它在我的 Windows 用户帐户下运行。有没有办法可以将我的 WCF 服务配置为在调用其他服务时使用 Windows 凭据? nunit 和 WCF 服务使用的端点配置是一样的。
  • 这就是我问的原因:你的配置是什么样的?远程 Web 服务需要什么样的身份验证?
  • 我已经添加了配置部分,您能否快速查看一下,如果设置不正确,请提出建议?
  • @Balaji:好的,你根本没有使用任何安全措施——现在的问题是:你调用的网络服务是否期望/需要任何类型的安全/身份验证?现在,WCF 服务根本不会提供任何东西.....
  • 是的,我正在调用的 Web 服务需要身份验证,传递我的 Windows 凭据应该可以工作。 Nunit 之所以有效,是因为它使用了我的 Windows 登录详细信息。当我从 WCF 客户端调用服务时,我无法弄清楚如何传递详细信息。你能说明一下吗?
【解决方案2】:

看起来您需要一些配置才能调用您的网络服务。

  • 这个配置在你的单元测试的配置文件中是正确的。
  • 但在您的 WCF 服务的配置文件中不正确或缺失。

当您有两个 dll 并且其中一个调用另一个时,则使用第一个 dll 的配置文件。但是,当您越过 WCF 跃点时,接管的是 WCF 服务的配置文件。

希望对你有帮助

设拉子

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2014-08-23
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多