采用wsHttpBinding的WCF服务能否通过Web引用而非服务引用调用?
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
wsHttpBindinguses SOAP 1.2 by default. The simplest fix is to add a newbasicHttpBindingendpoint 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:
wsHttpBindingdefaults to message-level security (<security mode="Message"/>), which ASMX doesn’t recognize. Switch toNoneorTransport(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:
- In Visual Studio, right-click your client project → Add → Service Reference.
- Click the Advanced button at the bottom of the dialog.
- Select Add Web Reference (the legacy option for ASMX-style proxies).
- 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

