我的 WCF 休息服务调用了两次我不知道确切的原因。当使用客户端应用程序进行调试时,它会被调用两次。谁能指出我出了什么问题...
服务声明:
[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 };
}
}
候选列表数据服务.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>
提前致谢
维杰