从Windows商店应用程序向WCF发送字符串

时间:2013-05-20 06:41:37

标签: c# wcf windows-store-apps app-config

我有一个Windows商店应用程序,在这个商店应用程序中,我有一个文本框,用户输入信息,然后被发送到我的WCF服务。

现在问题就在于此。当用户键入1-50个字符然后决定发送信息时,一切正常。但是..当用户键入超过50个字符时,我的应用程序无法发送信息。

我试图在app.config文件中更改/添加maxArrayLength,maxStringContentLength,maxBufferPoolSize和maxBufferSize。达到比以前更高的价值,但没有成功。

所以我的问题是:我能发送超过50个字符还是有限制?如果有可能发送超过50个字符..我该怎么做?

---------------------- EDIT --------------------

这是我将信息发送到WCF的方式

            var server = new EmployeeAssisterClient();

            var timeReportList = _timeReport.GetAll();

            foreach (var timeReport in timeReportList)
            {
                if (!result)
                    break;

                result = server.RegisterTimeAsync(new EmployeeAssisterWCF.TimeReport
                    {
                        CustomerId = timeReport.CustomerId,
                        Date = timeReport.Date,
                        InvoiceText = timeReport.InvoiceText,
                        TimeInvoiced = (int) timeReport.InvoicedTime,
                        TimeWorked = (int) timeReport.WorkedTime,
                        UserId = timeReport.UserId,
                    }).Result;
            }

WCF中的RegisterTime方法

public Boolean RegisterTime(TimeReport timeReport)

    {            
        var connection = new SqlConnection(_connectionString);
        var cmd = new SqlCommand("insert into TimeReport values (@employeeId, @customerNumber, @invoicedTime, @workedTime, @date, @invoiceText, @Invoiced)", connection);

        cmd.Parameters.Add(new SqlParameter("@employeeId", timeReport.UserId));
        cmd.Parameters.Add(new SqlParameter("@customerNumber", timeReport.CustomerId));
        cmd.Parameters.Add(new SqlParameter("@invoicedTime", timeReport.TimeInvoiced));
        cmd.Parameters.Add(new SqlParameter("@workedTime", timeReport.TimeWorked));
        cmd.Parameters.Add(new SqlParameter("@date", timeReport.Date));
        cmd.Parameters.Add(new SqlParameter("@invoiceText", timeReport.InvoiceText));
        cmd.Parameters.Add(new SqlParameter("@Invoiced", false));

        try
        {
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
        }
        catch (SqlException)
        {
            cmd.Connection.Close();
            return false;
        }
        finally
        {
            cmd.Connection.Close();
        }
        return true;
    }

我的绑定

<bindings>
  <netHttpBinding>
    <binding name="netHttpBindingConfig" maxReceivedMessageSize="2097152"
                 maxBufferSize="2097152" 
                 maxBufferPoolSize="2097152"> 
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </netHttpBinding>
</bindings>

此致 尼古拉斯

0 个答案:

没有答案