【发布时间】:2013-11-13 14:37:53
【问题描述】:
我是 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;
}
}
有人知道可能的原因吗?
【问题讨论】:
-
您如何托管服务?例如,您使用的是 IIS 还是控制台应用程序?服务的绑定和端点配置在哪里?
-
@Alberto IIS。以下是配置设置:
-
-
-
您是否尝试过将调试器附加到服务或使用 Fiddler 或其他工具来验证您是否确实在访问该服务?