Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebScriptServiceHostFactory vs WebServiceHostFactory

Tags:

asp.net

wcf

Can someone explain the difference between the two, when to use WebScriptServiceHostFactory vs WebServiceHostFactory? I understand when used they setup certain default behaviors on the endpoints so I don't have to. Otherwise the differences, is it just the WebScriptServiceHostFactory defaults to JSON messages, while WebServiceHostFactory defaults to XML (soap messages)? Using WebGet and WebInvoke, do both work on them, or does one not allow it? Also can I use UriTemplates, to build REST services, with either one?

like image 1000
Paritosh Avatar asked Aug 03 '26 00:08

Paritosh


1 Answers

The WebScriptServiceHostFactory is used almost exclusively to define services that will be consumed by the ASP.NET AJAX framework (it gives the JS client a "proxy" which can be used to call the service). If you're doing general-purpose WCF web (REST) programming, you should stick with the WebServiceHostFactory.

Some differences:

  • As you mentioned, the default response format is different (JSON in WScriptSHF, XML in WSHF)
  • UriTemplates are fully supported in WSHF, not in WScriptSHF
  • WebGet and WebInvoke work on both, but on WScriptSHF the only supported body style is WrappedRequest
  • Responses to calls to an endpoint created by WScriptSHF are wrapped in a JSON object; if the response to an operation (in JSON) was [1,2,3], the endpoint will return it as {"d":[1,2,3]}.

There may be others, but essentially, the guidance is to use the WScriptSHF only if you're using the ASP.NET AJAX framework (with the <asp:ScriptManager>) and the WSHF for everything else.

like image 178
carlosfigueira Avatar answered Aug 05 '26 19:08

carlosfigueira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!