0
我的WCF Rest服務調用兩次我不知道確切的原因。當用客戶端應用程序進行翻譯時,它會被調用兩次。任何人都可以指出我哪裏出了問題......WCF Rest服務被稱爲兩次
服務宣言:
[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;
}
}
Web配置:
<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>
在此先感謝
維傑