0

我是 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;
        }
    }

有人知道可能的原因吗?

4

1 回答 1

1

对于刚接触 WCF 的人来说,最好的建议(也许很明显以至于许多人忽略)是熟悉 WCF 跟踪和消息记录。WCF 跟踪功能提供了一种相对简单的内置方法来监视与 WCF 服务之间的通信。对于测试和调试环境,配置信息或详细活动跟踪并启用消息日志记录。在最初部署和测试新服务或向现有服务添加新操作和/或通信绑定时,活动跟踪和消息记录的组合应该证明是有益的。

以下链接提供了一个很好的概述: http:
//msdn.microsoft.com/en-us/library/ms733025.aspx
http://msdn.microsoft.com/en-us/library/aa702726.aspx

于 2013-11-02T18:49:27.213 回答