views:

153

answers:

1
  1. Is it required to use a RESTful service to be able to make a ajax call to a wcf service (for example: by using WebInvoke attribute on Operation contracts)
  2. Once a service is made RESTful by adding a webHttp binding on the service host, can the host have other endpoints as well? (wsHttp or netTcp)
  3. Is it required that the aspNetCompatibilityEnabled be set to true for a service that has webHttp binding (and can this setting coexist for other endpoints)
  4. I understand I can use both JQuery and ScriptManager for making WCF calls on the client. Why should I use one over the other?
+3  A: 

Answers

  1. No.
    AJAX is typically used for sending simple HTTP GET ("REST") requests. It doesn't have to be so. You could also format a payload using a SOAP envelope, and POST it to the endpoint. In that case the WCF service would have to be wsHttp or basicHttpBinding, at least. Here's an example of using VBScript to create and send a SOAP request, but you could do the same in Javascript. You can't use the more advanced SOAP extensions, like WS-Security, XML DigSig, and so on. Well, you could but it would be impractical. For example, I don't know of any XML canonicalization library in Javascript, which is essential for doing WS-Security or digital signatures. There are 17 similar obstacles. Result: you can't use the more advanced SOAP extensions when calling from Javascript.
    .
    If you use jQuery ajax, you'll need to use the beforeSend callback on the ajax request to set the SOAPAction header.
    .
    Having said that, it's a lot easier to process json in a Javascript program, than it is to walk the DOM of an XML document. In other words, you're better off using JSON/REST when connecting from Javascript to WCF, instead of SOAP. Sometimes it's not an option, I guess.

  2. Yes
    A WCF service can have multiple endpoints and they can listen on the same or different transports such as HTTP, net.tcp, net.pipe, or net.msmq.

  3. No. aspNetCompatibilityEnabled just enables some ASMX-like features on the server. It affects how the service is designed, and it is independent of the message signature. It does preclude the use of non-HTTP protocols. For more on this, see Wenlong Dong's article.

  4. as for which framework to use on the client - which is easier? I don't have experience with ScriptManager, but the decision criteria is pretty simple. jQuery works just fine, and is appropriate if you already use jQuery. If you don't have or want jQuery, you can use XmlHttpRequest to send SOAP or REST requests. If those are somehow inappropriate, use something else.

Cheeso
@Cheeso - If I use JQuery on the client to make a AJAX call, I assume the answer for (1) will be yes, since I now have to use Json as the response and this can be be done by applying the WebGet attribute and changing RequestFormat to Json? Wouldn't this essentially turn this service into a RESTful one?
DotnetDude
No. you can use jQuery ajax and specify dataType='xml', to indicate the type of data you're expecting from the server. If it's XMLthe response will not automatically be evaluated as a json value by jQuery.
Cheeso