无法引用 System.ServiceModel.EndpointNotFoundException
我试图捕捉这个异常:
System.ServiceModel.EndpointNotFoundException
但视觉工作室没有找到它。末尾没有红色破折号,如果我尝试在 System.ServiceModel 命名空间上使用 using,则 System.Web 中没有 ServiceModel。虽然来自 System.ServiceModel 命名空间 它位于.Net Framework 类库中。
有什么原因我无法参考它吗?
当我的应用程序无法访问我的网络服务时,我收到错误消息。
编辑: 目标框架是:3.5 未检查客户端框架。
编辑:我添加了 System.ServiceModel 命名空间,但显然(当时并不明显),我将其添加到类库而不是程序中。这就是整个麻烦所在。当建议我关闭并开始一个新项目,添加库时,它起作用了,所以我回去看了看。 VS 在重新打开时有所不同,很明显我已将 System.ServiceModel 添加到库而不是主项目中。
感谢您的帮助!
I'm trying to catch this exception:
System.ServiceModel.EndpointNotFoundException
But visual studio isn't finding it. There's no little red dash at the end, and if I try doing a using on the System.ServiceModel
namespace, there is no ServiceModel in System. Though from System.ServiceModel Namespace it is in the .Net Framework class library.
Is there a reason I cannot reference it?
I get the error when my application cannot access my web-service.
Edit:
Target framework is: 3.5
Client framework is not checked.
Edit: I'd added the System.ServiceModel namespace, but apparently (it wasn't obvious at the time), I'd added it to a class library instead of the program. That was the whole bother. When suggested that I close and start a new project, add the library, it worked, so I went back and looked. VS was different on re-open and it was obvious I'd added System.ServiceModel to the library and not the main project.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过将对
System.ServiceModel
的程序集引用添加到您的项目中?编辑以防万一出现问题,以下是有关如何操作的说明:
Have you tried adding the assembly reference to
System.ServiceModel
to your project?Edit Just in case this is the issue, here's instructions on how to do so:
两个要求:
后者可能是您的问题。 C# IDE 中的项目 + 属性、应用程序选项卡、目标框架设置。
Two requirements:
The latter is probably your issue. Project + Properties, Application tab, Target framework setting in the C# IDE.
(根据提问者的要求添加,以回应评论中的讨论。)
如果您肯定添加了参考文献,并且您肯定 em> 面向 .NET 3.0+,那么这个将会工作。
我刚刚在 VS 2008 中创建了一个针对 .NET 3.5(完整)的新项目,添加了对 System.ServiceModel 的引用,一切都按预期运行。
肯定还有其他问题。尝试看看是否可以在新的空白项目中做同样的事情。
(Added at the request of the asker, in response to discussions in comments.)
If you've definitely added the reference, and you're definitely targeting .NET 3.0+, then this will work.
I just created a new project targeting .NET 3.5 (full) in VS 2008, added the reference to
System.ServiceModel
, and everything works exactly as expected.Something else must be wrong. Try seeing if you can do the same thing in a new, blank project.
添加对 SYSTEM.SERVICEMODEL 的引用
我遇到了同样的问题,我有一个 VS2012 win 表单项目 .NET 3.5 客户端配置文件。
我想通过 VS2010 控制台项目 .NET 3.5 与 UPS API 集成
我将它拆开,抓取了一个 dll 和相关的 .cs 页面...它使用 System.ServiceModel 但我的 VS2012 项目不理解这一点...
添加对 SYSTEM.SERVICEMODEL 的引用为我解决了这个问题
Add Reference to SYSTEM.SERVICEMODEL
I had this same problem, I had a VS2012 win forms project .NET 3.5 client profile.
I wanted to integrate with UPS API via VS2010 Console project .NET 3.5
I hacked it apart, grabbed a dll and the pertianent .cs page... it was using System.ServiceModel but my VS2012 project did not understand this...
Adding a reference to SYSTEM.SERVICEMODEL solved this for me