0

WCF Rest サービスが 2 回呼び出されました。正確な理由はわかりませんでした。クライアント アプリケーションでデバッグすると、2 回呼び出されます。誰が何が悪かったのか教えてもらえますか...

サービス宣言:

    [ServiceContract]
        public interface IVoteCountService
        {
               [OperationContract]
            [WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat =                 WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare,
                UriTemplate = "/GetCandidate")]
            CandisteListResponse CandidateList();
}

[DataContract]
    public class CandisteListResponse
    {
        public CandidateList CandidateList { get;set;}
    }

サービス定義:

public CandisteListResponse CandidateList()
        {
            CandidateList objVoterList = new CandidateList();
            objVoterList = CandidateListDataService.GetCandidateList();

            if (objVoterList.Count > 0)
            {

                return new CandisteListResponse {  CandidateList = objVoterList };
            }
            else
            {

                return new CandisteListResponse { CandidateList = objVoterList };
            }
        }

CandidateListDataService.cs :

public class CandidateListDataService
    {
        public static CandidateList GetCandidateList()
        {
            CandidateList obj = new CandidateList();
            using (SqlConnection MyConnection = new SqlConnection(SqlServerDataSource.GetConnectionString()))
                try
                {
                    if (ConfigurationManager.AppSettings["SelectDB"] == "SQLServer")
                    {
                        {
                            SqlCommand MyCommand = new SqlCommand("usp_service_get_candidate", MyConnection);
                            MyCommand.CommandType = CommandType.StoredProcedure;
                            MyCommand.CommandTimeout = 56000;

                            MyConnection.Open();

                            using (SqlDataReader MyReader = MyCommand.ExecuteReader())
                            {

                                while (MyReader.Read())
                                {
                                    obj.Add(FillVoterInformation(MyReader));


                                }

                                MyReader.Close();
                                MyReader.Dispose();
                            }

                        }
                    }

                }
                catch (Exception ex)
                {
                    MyConnection.Dispose();

                }
                finally
                {
                    MyConnection.Dispose();

                }
            return obj;

        }


        private static Candidate FillVoterInformation(SqlDataReader MyDataRecord)
        {
            Candidate MyVoterlist = new Candidate();

            try
            {
                MyVoterlist.CODE = Convert.ToString(MyDataRecord["CODE"]);
                MyVoterlist.CNAME = Convert.ToString(MyDataRecord["CNAME"]);
                MyVoterlist.SH_NAM = Convert.ToString(MyDataRecord["SH_NAM"]);

                MyVoterlist.TV = (MyDataRecord["TV"] == DBNull.Value ? Convert.ToInt32(0) : Convert.ToInt32(MyDataRecord["TV"]));

                MyVoterlist.TVCNT = (MyDataRecord["TVCNT"] == DBNull.Value ? Convert.ToInt32(0) : Convert.ToInt32(MyDataRecord["TVCNT"]));
                MyVoterlist.ROW_NO = (MyDataRecord["ROW_NO"] == DBNull.Value ? Convert.ToInt32(0) : Convert.ToInt32(MyDataRecord["ROW_NO"]));

            }
            catch (Exception ex)
            {
                throw ex;

            }
            return MyVoterlist;

        }


    }

ウェブ構成:

<system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="streamWebHttpbinding" transferMode="Streamed"  maxReceivedMessageSize="1000000000000" receiveTimeout="01:00:00" sendTimeout="01:00:00" />
      </webHttpBinding>

    </bindings>
    <services>
      <service name="VoteCountService.VoteCountWCFService" behaviorConfiguration="ServiceBehaviour">
        <endpoint address ="" binding="webHttpBinding"  contract="VoteCountService.IVoteCountService" behaviorConfiguration="web" bindingConfiguration="streamWebHttpbinding" >
        </endpoint>
      </service>
      </services>
    <behaviors>
      <serviceBehaviors>
         <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
          <dataContractSerializer maxItemsInObjectGraph="10000000"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

前もって感謝します

ビジェイ

4

1 に答える 1

0

私のアプリケーションでは、次のようにデータタイム変換を使用しました

 private static Voter FillVoterInformation(SqlDataReader MyDataRecord)
            {
                Voter MyVoterlist = new Voter();

                try
                {
                  MyVoterlist.VOTERDOB = (MyDataRecord["VOTERDOB"] == DBNull.Value? Convert.ToDateTime(null): Convert.ToDateTime(MyDataRecord["VOTERDOB"]));
    }
    catch (Exception ex)
                {
                    throw ex;

                }
                return MyVoterlist;

            }

When I had analyzed TraceListner I Found that the DateTime Conversion Throws the following  following Exception.

"DateTime values that are greater than DateTime.MaxValue or smaller than DateTime.MinValue when converted to UTC cannot be serialized to JSON." 

I have Solved this issue by converting DateTime to UTC Time Following is the Code  

item.VOTERDOB = DateTime.SpecifyKind(item.VOTERDOB, DateTimeKind.Utc);

ありがとう

ビジェイ

于 2012-11-26T12:48:29.890 に答える