locked
Ajax auto-complete with WCF. RRS feed

  • Question

  • User355090264 posted

    I have an issue with ajax automplete textbox using WCF. I am working on 3-tier architecture so the service and client will be on different servers but for testing currently i've published my service to localhost and while consuming it in client the ajax textbox is not showing any results.
    I've two different endpoint one with wshttpbinding and the other one with webhttpbinding. The base address is same but the contracts are different. While calling the service method in code behind isntead of markup aspx page with binding changed to wshttpbinding it works fine but with webhttpbinding it returns an error saying "The remote server returned an unexpected response: (400) Bad Request."
    Below are the config files .Please help me in resolving this issue. Thanks in Advance!!

    --- Service side web.cofig--
    <system.serviceModel>
    	  <bindings>
    		  <webHttpBinding>
    			  <binding name="WebHttpBinding_IAjax" crossDomainScriptAccessEnabled="true" >
    				  <readerQuotas maxDepth="2147483647"
    
    maxStringContentLength="2147483647"
    
    maxArrayLength="2147483647"
    
    maxBytesPerRead="2147483647"
    
    maxNameTableCharCount="2147483647" />
    			 
    			  </binding>
    		  </webHttpBinding>
    	  </bindings>
       <services>
        <service behaviorConfiguration="EXService.EXBehavior" name="EX.Service.EXService">
        
         <endpoint address="War" binding="wsHttpBinding" contract="EX.Model.IWar">
          <identity>
           <dns value="localhost" />
          </identity>
         </endpoint>
    		
         <endpoint address="" binding="webHttpBinding" contract="EX.Model.IAjax" bindingConfiguration="WebHttpBinding_IAjax" behaviorConfiguration="ServiceAspNetAjaxBehavior">
    		 <identity>
    			 <dns value="localhost" />
    		 </identity>
         </endpoint>
         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
         <host>
          <baseAddresses>
           <add baseAddress="http://localhost/EXService/EXService.svc"/>
          </baseAddresses>
         </host>
        </service>
       </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="EXService.EXBehavior">
    			<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true" />
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
    	   <endpointBehaviors>
    			<behavior name="ServiceAspNetAjaxBehavior">
    				<webHttp/>
    			</behavior>
    		</endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    
    
    --- Client side web.config ----
    <system.serviceModel>
    		<bindings>
    			<wsHttpBinding>
    				<binding name="WSHttpBinding_IWar"/>
    			</wsHttpBinding>
    			<webHttpBinding>
    				<binding name="WebHttpBinding_IAjax"/>
    			</webHttpBinding>
    		</bindings>
    		<behaviors>
    			<endpointBehaviors>
    				<behavior name="WarBehaviour">
    					<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    				</behavior>
    				<behavior name="AjaxBehavior">
    					<webHttp/>
    				</behavior>
    			</endpointBehaviors>
    		</behaviors>
    		<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    		<client>
    			<endpoint address="http://localhost/EXService/EXService.svc" behaviorConfiguration="AjaxBehavior" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IAjax" contract="ServiceReference1.IAjax" name="WebHttpBinding_IAjax"/>
    			<endpoint address="http://localhost/EXService/EXService.svc/War" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWar" contract="ServiceReference1.IWar" name="WSHttpBinding_IWar">
    				<identity>
    					<dns value="localhost"/>
    				</identity>
    			</endpoint>
    		</client>
    	</system.serviceModel>
    
    ---client aspx page ----
    
     <ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"
                        EnableCaching="true"
                        BehaviorID="AutoCompleteEx"
                        MinimumPrefixLength="4"
                        TargetControlID="txtDef"
                        ServicePath="http://localhost/EXService/EXService.svc"
                        ServiceMethod="GetCompletionList"
                        CompletionInterval="1000"
                        CompletionSetCount="20"
                        DelimiterCharacters=";:"
                        ShowOnlyCurrentWordInCompletionListItem="true">
                        <Animations>
                         <OnShow>
                          <Sequence>
                            <%-- Make the completion list transparent and then show it --%>
                            <OpacityAction Opacity="0" />
                            <HideAction Visible="true" />
                            <%--
                                Cache the original size of the completion list the first time
                                the animation is played and then set it to zero --%>
                            <ScriptAction Script="// Cache the size and setup the initial size
                                    var behavior = $find('AutoCompleteEx');
                                    if (!behavior._height) {
                                        var target = behavior.get_completionList();
                                        behavior._height = target.offsetHeight - 2;
                                        target.style.height = '0px';
                                    }" />
                            <%-- Expand from 0px to the appropriate size while fading in --%>
                            <Parallel Duration=".4">
                                 <FadeIn />
                                  <Length PropertyKey="height" StartValue="0"
                                    EndValueScript="$find('AutoCompleteEx')._height" />
                            </Parallel>
                           </Sequence>
                        </OnShow>
                      <OnHide>
                        <%--  Collapse down to 0px and fade out --%>
                        <Parallel Duration=".4">
                         <FadeOut />
                         <Length PropertyKey="height" StartValueScript=
    	                    "$find('AutoCompleteEx')._height" EndValue="0" />
                        </Parallel>
                       </OnHide>
                    </Animations>
                   </ajaxToolkit:AutoCompleteExtender>
    ---Operation Contract---
    
    [OperationContract]
           
           [WebInvoke(Method="GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
           
            string[] GetCompletionList(string prefixText);
    Monday, October 14, 2013 3:58 PM

Answers