</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
同时,对 IWCFForumService.cs 代码进行修改,代码如下。另外,增加 DataContact 类 – MessageInfo.cs,其中的成员变量
通过 DataMemeber 进行标识,MessageInfo 将作为 DataContract 在 IWCFForumService 中使用。MessageInfo 是一个独立
的类,标识为 public,允许外部系统访问。
WCFForumService 则是对 IWCFForumService 接口的实现类,代码如下:
private string strConn = ConfigurationManager.ConnectionStrings["EntLibForum"].ConnectionString;
public string GetMessage(int messageID)
{
string msg = string.Empty;
string strSelect = "Select Message From yaf_message where MessageID=" + messageID.ToString();
using (SqlConnection connection = new SqlConnection(strConn))
{
SqlCommand command = new SqlCommand(strSelect, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
if (reader.Read())
{
msg = reader["Message"].ToString().Trim();
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
return msg;
}
public MessageInfo GetMessageInfo(int messageID)
{