在 WCF 客户端中调用某些服务时出错

Error in Calling some service in WCF Client

当我调用这个服务方法时:

StaffServiceClient _Service = new StaffServiceClient();
Table_StaffInfo item = _Service.GetStaffById(10);

我收到一个错误:

An error occurred while receiving the HTTP response to http://localhost:8008/StaffService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

但是当我调用另一个服务方法时:

StaffServiceClient _Service = new StaffServiceClient();
List<spStaffList_Result> list = _Service.GetStaffList().ToList();

程序有效。

您的方法 GetStaffById 内部失败。也许它在接收数据时有问题(如果只是一个 int 则不太可能)也许它在发送数据时有问题(你的类型 Table_StaffInfo 是否具有 DataContract / DataMember 属性?)或者它只是抛出一个异常.

您将需要调试您的服务。在方法中打个断点,看看它会将你带到哪里。

对于初学者,请忽略 int 参数,只在方法中放置一个 return null;。如果可行,则与您的连接或服务器设置无关,您需要调试代码。