WCF service does not return jQuery value

I am having trouble getting jquery to get results from WCF service. I host the WCF service in IIS, and when I attach the debugger to this process, I see that the code has been processed successfully. However, when it accesses the callback in jquery, there is no data

I set the trace in the wcf service and there are no errors. It seems that the data is lost after the wcf service method has completed.

Here is the jquery code that calls the service:

$.get("http://ecopssvc:6970/ecopsService.svc/Echo", {echoThis: "please work"}, function(data) {
            alert("Data Loaded: " + data);
        });

Here is the wcf configuration:

    <system.serviceModel>
    <services>
      <service name="EcopsWebServices.EcopsService" behaviorConfiguration="EcopsServiceBehaviours">
        <endpoint address="" behaviorConfiguration="WebBehaviour"
          binding="webHttpBinding" bindingConfiguration="" contract="EcopsWebServices.IEcopsServiceContract" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebBehaviour">
          <webHttp />
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="EcopsServiceBehaviours">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Here is the service contract:

    [ServiceContract]
public interface IEcopsServiceContract
{    
    [WebGet]
    [OperationContract]
    string Echo(string echoThis);

}

Here is the service implementation:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class EcopsService : IEcopsServiceContract
    {

        #region IEcopsServiceContract Members

        public string Echo(string echoThis)
        {
            return string.Format("You sent this '{0}'.", echoThis);
        }

        #endregion
    }

Help someone !!!

+3
source share
3 answers

factory WebScriptServiceHostFactory .svc. , WCF - . :

WCF:

[ServiceContract]
public interface IService1
{
    [WebGet]
    [OperationContract]
    string Echo(string echoThis);
}

public class Service1 : IService1
{
    public string Echo(string echoThis)
    {
        return string.Format("You sent this '{0}'.", echoThis);
    }
}

web.config:

<system.serviceModel>
  <services>
    <service name="ToDD.Service1" 
             behaviorConfiguration="ToDD.Service1Behavior">
      <endpoint address="" 
                binding="webHttpBinding" 
                contract="ToDD.IService1" />
      <endpoint address="mex" 
                binding="mexHttpBinding" 
                contract="IMetadataExchange"/>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ToDD.Service1Behavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

service1.svc:

<%@ ServiceHost 
    Language="C#" 
    Debug="true" 
    Service="ToDD.Service1" 
    CodeBehind="Service1.svc.cs" 
    Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"
%>

index.htm:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    <script type="text/javascript" src="jquery-1.4.1.js"></script>
    <script type="text/javascript">
    $(function() {
        $.getJSON('http://localhost:4660/service1.svc/Echo', { 
            echoThis: 'please work' }, 
            function(data) {
                alert(data.d);
            }
        );
    });
    </script>
</head>
<body>
</body>
</html>
+2

2 :

  • - IE8, Firebug Firefox. , , WCF, , .

  • Fiddler HTTP- .

0

! , - . , , , , , .

0

Source: https://habr.com/ru/post/1736295/


All Articles