WCF服务不会将响应返回给模型(MVP)C# [英] WCF Service does not return response to model (MVP) C#

查看:65
本文介绍了WCF服务不会将响应返回给模型(MVP)C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用winforms创建了一个项目,并使用了mvp模式.
WCF服务处理数据控件.
从Bussines对象到Data Transfer对象并返回.
一切正常,直到return语句为止.

使用显示较少客户的sql语句对其进行了测试.
找到了问题,但在不把整个模式都弄乱的情况下就想不出解决办法.
它最多显示149个客户.当我在sql语句中更改条件时,要显示149条以上的记录,然后它将在返回响应时停止,并在10分钟后进入超时.
可能会限制容量吗?


这是模型中用于发出请求和响应的方法.

  public  IList< KlantModel> GetKlanten(字符串 sortExpression)
{
     var  request = PrepareRequest( new  KlantRequest());

    request.LoadOptions =  字符串 [] {"  Klanten"};
    request.Criteria =  KlantCriteria {SortExpression = sortExpression};
     var  response = Client.GetKlanten(request);

    // 如果(response.CorrelationId!= request.RequestId)
    // 抛出新的ApplicationException("GetKlanten:RequestId和CorrelationId不匹配."); 

    // 如果(response.Acknowledge!= AcknowledgeType.Success)
    // 抛出新的ApplicationException(response.Message); 

    返回 Mapper.FromDataTransferObjects(response.Klanten);
} 



该请求通过wcf.service获取所有数据.
但是当服务要返回响应时.它不会产生错误,但是会在10分钟后超时. (请参见下面的代码)

public KlantResponse GetKlanten(KlantRequest request)
{
    var response = new KlantResponse(request.RequestId);

        IEnumerable<Klant> klanten;
        klanten = _klantDao.GetKlanten(sort);

        response.Klanten = klanten.Select(c =>
        //Transfer BO to DTO
        DataTransferObjectMapper.Mapper.ToDataTransferObject(c)).ToList();
    //This is the part where it doesn''t do anything anymore
    return response;
}



web.config也配置为< servicemodel> ;.

 <   system.serviceModel  > 
    <  服务 > 
      <  服务    ="   behaviorAction" 名称   NameSpace.Service " <  端点    ="   wsHttpBinding"  bindingConfiguration    bindingAction"   合同  ="  NameSpace.IService" <  身份 > 
            <   dns     ="   localhost" > 
          <  /identity  > 
        <  /endpoint  > 
        <  端点    ="   mex" 绑定   mexHttpBinding"   合同  ="  IMetadataExchange" > 
      <  /service  > 
    <  /服务 > 
    <  行为 > 
      <   serviceBehaviors  > 
        <  行为    ="   behaviorAction" <   serviceMetadata     ="   true" > 
          <   serviceDebug     ="   true" > 
        <  /行为 > 
      <  /serviceBehaviors  > 
    <  /行为 > 
    <  绑定 > 
      <   wsHttpBinding  > 
        <  绑定    ="   bindingAction"  transactionFlow    false"    sendTimeout   ="  00:30:00"  receiveTimeout   ="  > 
          <   reliableSession     ="   true" > 
        <  /binding  > 
      <  /wsHttpBinding  > 
    <  /bindings  > 
  <  /system.serviceModel  > 
<  /servicemodel  >  



响应由响应类处理. Klantrequest.cs

 [DataContract(Namespace ="http://www.yourcompany.com/types/")]
公共类KlantRequest:RequestBase
{
    ///<  摘要 > 
    ///选择标准和排序顺序
    ///<  /summary  > 
    [DataMember]
    公共KlantCriteria标准;

    ///<  摘要 > 
    ///Klant对象.
    ///<  /summary  > 
    [DataMember]
    公共KlantDto Klant;
} 




有谁知道怎么回事就没有任何错误的

预先感谢.

解决方案

解决了.

是否在模型和Starters项目中都更改了app.config. (必须同时更改两个app.configs)

发生了什么变化:
-全部超时10分钟.
-读者配额.
-maxBufferPoolSize和maxReceivedMessageSize.

 <  绑定   名称  ="     closeTimeout   ="     openTimeout    00:10:00"  receiveTimeout    00:10:00"  sendTimeout   ="   bypa ssProxyOnLocal   ="     transactionFlow   ="     hostNameComparisonMode   ="     maxBufferPoolSize   ="  2147483647"  maxReceivedMessageSize   ="     ="  文本"  textEncoding   ="   useDefaultWebProxy    true"     allowCookies   ="  false" <   readerQuotas     ="   32"  maxStringContentLength   > 8192"     maxArrayLength   ="  16384"  maxBytesPerRead    4096"  maxNameTableCharCount   ="  >/ > 
  <   reliableSession     ="   inactivityTimeout    00:10 :00" 已启用   true" > 
<  /binding  >                                              pre> 

非常感谢您的帮助.


I created a project with winforms and used the mvp pattern.
The WCF service handles the data control.
From Bussines objects tot Data Transfer objects and back.
Everything works fine until the return statement.

Tested it with an sql statement that shows less customers.
Found the problem but can''t figure out a solution without throwing the whole pattern over.
It shows up to 149 customers. When I change the criteria in the sql statement, to more then 149 records to show then it stops at return response and goes in Time Out after 10 minutes.
Maybe a limit on the capacity?


This is a method in the model that is used to make the request and the response.

public IList<KlantModel> GetKlanten(string sortExpression)
{
    var request = PrepareRequest(new KlantRequest());

    request.LoadOptions = new string[] { "Klanten" };
    request.Criteria = new KlantCriteria { SortExpression = sortExpression };
    var response = Client.GetKlanten(request);

    //if (response.CorrelationId != request.RequestId)
    //    throw new ApplicationException("GetKlanten: RequestId and CorrelationId do not match.");

    //if (response.Acknowledge != AcknowledgeType.Success)
    //    throw new ApplicationException(response.Message);

    return Mapper.FromDataTransferObjects(response.Klanten);
}



The request works gets all the data with the wcf.service.
But when the service wants to return the response. It doesn''t give an error but goes in time out after 10 min. (See code below)

public KlantResponse GetKlanten(KlantRequest request)
{
    var response = new KlantResponse(request.RequestId);

        IEnumerable<Klant> klanten;
        klanten = _klantDao.GetKlanten(sort);

        response.Klanten = klanten.Select(c =>
        //Transfer BO to DTO
        DataTransferObjectMapper.Mapper.ToDataTransferObject(c)).ToList();
    //This is the part where it doesn''t do anything anymore
    return response;
}



The web.config is configured also <servicemodel>.

<system.serviceModel>
    <services>
      <service behaviorConfiguration="behaviorAction" name="NameSpace.Service">
        <endpoint binding="wsHttpBinding" bindingConfiguration="bindingAction" contract="NameSpace.IService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behaviorAction">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="bindingAction" transactionFlow="false" sendTimeout="00:30:00" receiveTimeout="00:30:00">
          <reliableSession enabled="true"/>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</servicemodel>



the response is handled with the response class. Klantrequest.cs

[DataContract(Namespace = "http://www.yourcompany.com/types/")]
public class KlantRequest : RequestBase
{
    /// <summary>
    /// Selection criteria and sort order
    /// </summary>
    [DataMember]
    public KlantCriteria Criteria;

    /// <summary>
    /// Klant object.
    /// </summary>
    [DataMember]
    public KlantDto Klant;
}




Does anyone knows how it comes that just the return doesn''t work without any error?

Thanks in advance.

解决方案

Worked out.

Did change app.config in both the model and the Starters project. (had to change in both app.configs)

What changed:
- Time out all to 10 minutes.
- the readerQuotas.
- maxBufferPoolSize and maxReceivedMessageSize.

<binding name="WSHttpBinding_IOVAService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
  <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true"/>
</binding>



Thanks a lot for helping.


这篇关于WCF服务不会将响应返回给模型(MVP)C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆