我是WCF技术的新手。我目前的问题是我的Windows窗体应用程序没有得到wcf程序的响应。这是我的Windows窗体应用程序的代码:
WCFService.PMSService obj = new WCFService.PMSService();
string xx = obj.Test("Hello");
MessageBox.Show(xx);
我的Windows窗体应用程序挂起了这一行 - > string xx = obj.Test(“Hello”);
以下是我的程序wcf的代码:
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IPMSService
{
[OperationContract]
string DetermineGender(PersonalInfo pInfo);
[OperationContract]
string Test(string val);
}
[DataContract]
public enum Gender
{
[EnumMember]
Male,
[EnumMember]
Female,
[EnumMember]
None
}
// Use a data contract as illustrated in the sample below to add composite types to service operations
[DataContract]
public class PersonalInfo
{
[DataMember]
public string name
{
get { return name; }
set { name = value; }
}
[DataMember]
public string surname
{
get { return surname; }
set { surname = value; }
}
[DataMember]
public string idNo
{
get { return idNo; }
set { idNo = value; }
}
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class PMSService : IPMSService
{
public string DetermineGender(PersonalInfo pInfo)
{
Gender Result = Gender.None;
int idNo = Convert.ToInt32(pInfo.idNo.Substring(6, 4));
if (idNo >= 5000)
Result = Gender.Male;
else
Result = Gender.Female;
return Result.ToString();
}
public string Test(string val)
{
return "U passed " + val;
}
}
有人知道可能的原因吗?
答案 0 :(得分:1)
对于刚接触WCF的人来说,最好的建议(也许很明显,许多人忽视)是熟悉WCF跟踪和消息记录。 WCF跟踪功能提供了一种相对简单的内置方法来监视与WCF服务之间的通信。对于测试和调试环境,请配置信息或详细活动跟踪并启用消息日志记录。在最初部署和测试新服务或向现有服务添加新操作和/或通信绑定时,活动跟踪和消息记录的组合应该证明是有益的。
以下链接提供了一个很好的概述:
http://msdn.microsoft.com/en-us/library/ms733025.aspx
http://msdn.microsoft.com/en-us/library/aa702726.aspx