【发布时间】:2012-06-23 23:09:23
【问题描述】:
刚刚使用 IIS 7.5 在我公司的服务器上部署了我的 WCF 服务,一切似乎都运行良好。但是当我设置我的客户端应用程序并添加对服务器的服务器引用然后使用此代码时。
ServerReference.ServiceClient client = new ServerReference.ServiceClient();
var s = client.GetBrand("Audi", false);
我得到一个异常,说“对象引用未设置为对象的实例”。 s 对象不应为空(我们在 localhost 上尝试了该服务,我们将其全部放在它工作的同一个项目中)。
您查看了 stackstrace,它看起来像这样。
21.6.2012 16:16:29
对象引用未设置为对象的实例。
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
有什么建议吗?? P.S 托管 WCF 服务的 CPU 没有 Visual Studio,所以我无法通过它进行调试
【问题讨论】:
-
WcfTestClient 是否适用于托管服务?缩小范围以查看它是您的实现,还是服务未能初始化。合同也可能已更改(取决于您上次获取元数据的时间)可能导致服务无法实例化。
标签: c# .net wcf exception-handling wcf-client