Call WCF Service Through Javascript, AJAX, or JQuery
        Posted  
        
            by 
                obautista
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by obautista
        
        
        
        Published on 2011-01-13T03:42:17Z
        Indexed on 
            2011/01/13
            3:53 UTC
        
        
        Read the original article
        Hit count: 406
        
I created a number of standard WCF Services (Service Contract and Host (svc) are in separate assemblies). I fired up a Web Site in IIS to host the Services (i.e., address is http://services:1000/wcfservices.svc).
Then in my Web Site project I added the reference. I am able to call the services normally. I am needed to call some of the services client side. Not sure if I should be looking at articles calling WCF services through AJAX, JQuery, or JSON enabled WCF Services. Can anyone provide any thoughts or experience with configuring as such?
Some of the changes I made was adding the following to the Operation Contract:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "SetFoo")]
void SetFoo(string Id);
Then this above the implementation of the interface:
[AspNetCompatibilityRequirements(RequirementsMode = 
                            AspNetCompatibilityRequirementsMode.Allowed)]
Then in the service webconfig I have this (parens are angle brackets):
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
  <baseAddressPrefixFilters>
    <add prefix="http://services:1000/wcfservices.svc/"/>>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
Then in the client side I attempted this:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    <compositeScript>
        <Scripts>
            <asp:ScriptReference 
                      Path="http://Flixsit:1000/FlixsitWebServices.svc" />
        </Scripts>
    </CompositeScript>
</asp:ScriptManagerProxy>
I am attempting to call the service like this in javascript:
wcfservices.SetFoo(string Id);  
Nothing is working. If it is idea or a better solution to call JSON enable, JQuery, etc....I am willing to make any changes.
Thanks for any suggestions/tips provided....
© Stack Overflow or respective owner