0

以前の .NET Web サービスを WCF サービスに変更したいのは、Web サービスで Android アプリケーションの純粋な JSON 変数をポストしたいからです。これが私がこれまでに行ったことであり、まだエラーが発生します。このコードを修正するには?

私のIService.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.ServiceModel.Activation;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Runtime.Serialization.Json;

public class Service : IService
{
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "tampil")]
    public String GetReport()
    {
        List<Report> reports = new List<Report>();
        string connectionString = ConfigurationManager.ConnectionStrings["ConnWf"].ConnectionString;
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            string sql = "select type, sum(OrderQty) as total from tbl_weeklyflash_ID where type <> 'NULL' group by type";
            connection.Open();

            SqlCommand command = new SqlCommand(sql, connection);
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                Report report = new Report();
                report.type = reader["type"].ToString();
                report.total = reader["total"].ToString();
                reports.Add(report);
            }
        }

        MemoryStream stream = new MemoryStream();
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Report[]));
        serializer.WriteObject(stream, reports.ToArray());
        stream.Position = 0;
        StreamReader streamReader = new StreamReader(stream);
        return streamReader.ReadToEnd();
    }
}

私の Service.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.ServiceModel.Activation;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Runtime.Serialization.Json;

public class Service : IService
{
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "tampil")]
    public String GetReport()
    {
        List<Report> reports = new List<Report>();
        string connectionString = ConfigurationManager.ConnectionStrings["ConnWf"].ConnectionString;
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            string sql = "select type, sum(OrderQty) as total from tbl_weeklyflash_ID where type <> 'NULL' group by type";
            connection.Open();

            SqlCommand command = new SqlCommand(sql, connection);
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                Report report = new Report();
                report.type = reader["type"].ToString();
                report.total = reader["total"].ToString();
                reports.Add(report);
            }
        }

        MemoryStream stream = new MemoryStream();
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Report[]));
        serializer.WriteObject(stream, reports.ToArray());
        stream.Position = 0;
        StreamReader streamReader = new StreamReader(stream);
        return streamReader.ReadToEnd();
    }
}
4

0 に答える 0