You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

采用wsHttpBinding的WCF服务能否通过Web引用而非服务引用调用?

Can a wsHttpBinding WCF Service Be Called via Web Reference Instead of Service Reference?

Great question! The short answer is yes, you can make this work, but there are important limitations and configuration changes required since Web References are built for the older ASMX web service model, not full-featured WCF services.

Key Context to Know

First, a quick breakdown to set the stage:

  • Web References generate proxy classes that inherit from SoapHttpClientProtocol, designed exclusively for legacy ASMX (SOAP 1.1) services.
  • Service References create WCF-native proxies inheriting from ClientBase<T>, which fully support WCF’s advanced features like WS-Security, reliable messaging, and SOAP 1.2.

Since wsHttpBinding defaults to WCF-specific behaviors that ASMX can’t understand, you’ll need to tweak your service configuration to bridge the compatibility gap.

Required Configuration Adjustments

To get a Web Reference working with your wsHttpBinding WCF service, modify your service’s web.config/app.config to disable WCF-exclusive features:

  • Switch to SOAP 1.1: Web References only support SOAP 1.1, but wsHttpBinding uses SOAP 1.2 by default. The simplest fix is to add a new basicHttpBinding endpoint to your service (it defaults to SOAP 1.1 and is ASMX-compatible). Alternatively, you can create a custom binding that enforces SOAP 1.1 for your existing wsHttpBinding.
  • Simplify security settings: wsHttpBinding defaults to message-level security (<security mode="Message"/>), which ASMX doesn’t recognize. Switch to None or Transport (for HTTPS) instead:
    <bindings>
      <wsHttpBinding>
        <binding name="CompatibleWsHttpBinding">
          <security mode="None"/>
          <!-- Use this for HTTPS: <security mode="Transport"/> -->
        </binding>
      </wsHttpBinding>
    </bindings>
    
  • Disable advanced WCF features: Turn off reliable messaging, transaction flows, or any other WCF-specific behaviors that aren’t supported by ASMX.

How to Add the Web Reference

Once your service is configured for compatibility:

  1. In Visual Studio, right-click your client project → Add → Service Reference.
  2. Click the Advanced button at the bottom of the dialog.
  3. Select Add Web Reference (the legacy option for ASMX-style proxies).
  4. Enter your WCF service’s WSDL URL (e.g., http://your-service-url/Service.svc?wsdl) and click Add Reference.

Critical Caveats

  • Limited feature support: Web References will fail if your service uses WCF-exclusive features like duplex communication, WS-ReliableMessaging, custom data contract behaviors, or message-level security. You’ll get runtime errors or failed calls if these are enabled.
  • Legacy tech warning: Web References are deprecated by Microsoft—Service References (or newer alternatives like HttpClient for REST) are the recommended approach for WCF services. Using Web References will limit your ability to leverage WCF’s full capabilities and may create maintenance issues long-term.

Final Recommendation

Stick with Service References whenever possible—they’re built to work seamlessly with wsHttpBinding and all its features. Only use Web References if you have a hard requirement (e.g., supporting an older client that can’t use WCF proxies).

内容的提问来源于stack exchange,提问作者Rana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:30:14