Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从jquery进行多个并行WCF服务调用_Wcf_Json_Jquery_Wcf Client - Fatal编程技术网

如何从jquery进行多个并行WCF服务调用

如何从jquery进行多个并行WCF服务调用,wcf,json,jquery,wcf-client,Wcf,Json,Jquery,Wcf Client,我必须通过使用jquery在指定的时间间隔后更新网页的不同区域来进行多个WCF服务调用。如果我只对WCF服务进行一次调用,它可以正常工作,但是当有两个或更多并行调用WCF服务时,不会收到响应 所有服务调用都是在指定的时间间隔后进行的。以下是其中一个的代码: var type = "POST"; var contentType = "application/json; charset=utf-8"; var dataType = "json"; var processData = true; f

我必须通过使用jquery在指定的时间间隔后更新网页的不同区域来进行多个WCF服务调用。如果我只对WCF服务进行一次调用,它可以正常工作,但是当有两个或更多并行调用WCF服务时,不会收到响应

所有服务调用都是在指定的时间间隔后进行的。以下是其中一个的代码:

var type = "POST";
var contentType = "application/json; charset=utf-8";
var dataType = "json";
var processData = true;

function LoadData()
{
  var url = serviceURL;
  var data = '{}';
  CallService(url, data, LoadDataSuccess);
}

function LoadDataSuccess(result)
{
  if (dataType == "json")
  {
   //other code...

    setTimeout("LoadData()", 5000);
  }
}

function CallService(url, data, SuccessMethod)
{
  $.ajax({
    type: type, //GET or POST or PUT or DELETE verb
    url: url, // Location of the service
    data: data, //Data sent to server
    contentType: contentType, // content type sent to server
    dataType: dataType, //Expected data format from server
    processdata: processData, //True or False
    success: function (msg)
    {
      SuccessMethod(msg);
    },
    error: ServiceFailed
  });
}

function ServiceFailed(result)
{
  alert('Service call failed: ' + result.status + '' + result.statusText);
  type = null; contentType = null; dataType = null; processData = null;
}
我的wcf服务如下所示:

public interface ITestService
  {
    [OperationContract]
    [WebInvoke(Method = "POST",
               BodyStyle = WebMessageBodyStyle.Wrapped,
               ResponseFormat = WebMessageFormat.Json,
               RequestFormat = WebMessageFormat.Json)]
    List<Data> GetData();

    [OperationContract]
    [WebInvoke(Method = "POST",
               BodyStyle = WebMessageBodyStyle.Wrapped,
               ResponseFormat = WebMessageFormat.Json,
               RequestFormat = WebMessageFormat.Json)]
    List<Data> GetUser();

    [OperationContract]
    [WebInvoke(Method = "POST",
               BodyStyle = WebMessageBodyStyle.Wrapped,
               ResponseFormat = WebMessageFormat.Json,
               RequestFormat = WebMessageFormat.Json)]
    List<Data> GetCustomer();
  }
<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <behaviors>
      <endpointBehaviors>
        <behavior name="EndpBehavior"> 
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors> 
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior> 
        <behavior name=""> 
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior> 
      </serviceBehaviors>  
    </behaviors>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="TestService">
        <endpoint address="" binding="webHttpBinding" contract="ITestService" behaviorConfiguration="EndpBehavior"/>
      </service>
    </services>
</system.serviceModel>
公共接口ITestService
{
[经营合同]
[WebInvoke(Method=“POST”,
BodyStyle=WebMessageBodyStyle.Wrapped,
ResponseFormat=WebMessageFormat.Json,
RequestFormat=WebMessageFormat.Json)]
List GetData();
[经营合同]
[WebInvoke(Method=“POST”,
BodyStyle=WebMessageBodyStyle.Wrapped,
ResponseFormat=WebMessageFormat.Json,
RequestFormat=WebMessageFormat.Json)]
List GetUser();
[经营合同]
[WebInvoke(Method=“POST”,
BodyStyle=WebMessageBodyStyle.Wrapped,
ResponseFormat=WebMessageFormat.Json,
RequestFormat=WebMessageFormat.Json)]
列出GetCustomer();
}
配置如下所示:

public interface ITestService
  {
    [OperationContract]
    [WebInvoke(Method = "POST",
               BodyStyle = WebMessageBodyStyle.Wrapped,
               ResponseFormat = WebMessageFormat.Json,
               RequestFormat = WebMessageFormat.Json)]
    List<Data> GetData();

    [OperationContract]
    [WebInvoke(Method = "POST",
               BodyStyle = WebMessageBodyStyle.Wrapped,
               ResponseFormat = WebMessageFormat.Json,
               RequestFormat = WebMessageFormat.Json)]
    List<Data> GetUser();

    [OperationContract]
    [WebInvoke(Method = "POST",
               BodyStyle = WebMessageBodyStyle.Wrapped,
               ResponseFormat = WebMessageFormat.Json,
               RequestFormat = WebMessageFormat.Json)]
    List<Data> GetCustomer();
  }
<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <behaviors>
      <endpointBehaviors>
        <behavior name="EndpBehavior"> 
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors> 
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior> 
        <behavior name=""> 
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior> 
      </serviceBehaviors>  
    </behaviors>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="TestService">
        <endpoint address="" binding="webHttpBinding" contract="ITestService" behaviorConfiguration="EndpBehavior"/>
      </service>
    </services>
</system.serviceModel>


你说的“未收到响应”是什么意思?你试过在服务器上调试或使用Fiddler吗?@Buh,是的,我试过了。每当我同时进行两个服务调用时,没有一个服务以其各自的回调(成功)方法返回。但是,如果我在前一个服务的回调(success)方法中进行一个服务调用并进行另一个服务调用,那么它就可以正常工作。但是,我必须马上打电话。我要明确地说清楚。。。。当你同时打两个电话,看Fiddler的时候,你可以看到两个请求都消失了,你可以看到两个回复都回来了,好吗?它们看起来都很整齐?