Providing Ajax-enabled WCF Service for C # Code

I created an "Ajax-enabled WCF service". I can use the service from javascript code and the WebService works as intended. But I want to write an ATP around it. So I am adding webservice as "Service Reference" to my ATP project. Then I use the webservice call as usual. This all compiles fine. But when I run ATP it throws this error to me.

"System.InvalidOperationException: Could not find an endpoint element named ServiceReference1.IWCFService and the ServiceReference1.IWCFService contract in the ServiceModel client configuration section. This may be because the configuration file was not found for your application, or because the client cannot find an endpoint element matching this name.

This is what I have in the ATP App.config file.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IWCFService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://yashworkspace/BSS/WS/ServiceReference1.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWCFService"
            contract="ServiceReference1.IWCFService" name="BasicHttpBinding_IWCFService" />
    </client>
<services>
    <service name="ServiceReference1.WCFService">
        <endpoint address="http://yashworkspace/BSS/WS/ServiceReference1.svc" behaviorConfiguration="org.proj.WebServices.WCFServiceAspNetAjaxBehavior"
                binding="webHttpBinding" contract="org.proj.WebServices.IWCFService" />
    </service>
</services>
<behaviors>
    <endpointBehaviors>
        <behavior name="org.proj.WebServices.WCFServiceAspNetAjaxBehavior">
            <enableWebScript />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
        <behavior name="">
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
    </serviceBehaviors>
</behaviors>
</system.serviceModel>

      

Please let me know what could have gone wrong? I have a normal WCF service and it works fine.

Please, help.

Regards, Yash

+3


source to share


2 answers


The above answer from Drew Marsh is partially correct. But the main question is solved as follows. Additionally, the problem here is when u expose WCF as an ajax enabled WCF service, it communicates using JSON. When you call the same service from C # code, it calls it using a SOAP request. Therefore, you need to configure the service to accept both JSON and SOAP requests. So, in the "Services" section, you need to configure it as follows:

<services>
      <service name="ServiceReference1.WCFService">
          <endpoint address="" behaviorConfiguration="org.proj.WebServices.WCFServiceAspNetAjaxBehavior"
            binding="webHttpBinding" contract="org.proj.WebServices.IWCFService"  />
          <endpoint address="soapreq" behaviorConfiguration="org.proj.WebServices.MyServiceSOAPBehaviour" bindingConfiguration="BasicHttpBinding_IUpdateService"
                  binding="basicHttpBinding" contract="org.proj.WebServices.IWCFService" name="ServiceReference1.IWCFService" />
      </service>
  </services>

      



In the Behavior section, you need to customize the behavior of your endpoint as follows.

<endpointBehaviors>
          <behavior name="org.proj.WebServices.WCFServiceAspNetAjaxBehavior">
              <enableWebScript />
          </behavior>
          <behavior name="org.proj.WebServices.MyServiceSOAPBehaviour">
          </behavior>
      </endpointBehaviors>

      

+1


source


The problem is that the endpoint name doesn't match what the client instance is looking for:

<endpoint address="http://yashworkspace/BSS/WS/ServiceReference1.svc" 
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWCFService" 
        contract="ServiceReference1.IWCFService" name="BasicHttpBinding_IWCFService" /> 

      



As per the error message, it expects the name to be as well "ServiceReference1.IWCFService"

, so you are the endpoint you want.

<endpoint address="http://yashworkspace/BSS/WS/ServiceReference1.svc" 
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWCFService" 
        contract="ServiceReference1.IWCFService" name="ServiceReference1.IWCFService" /> 

      

0


source







All Articles