添加服务引用不生成代理 [英] Add Service Reference doesn't generate proxy

查看:53
本文介绍了添加服务引用不生成代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道还有其他类似的问题,但我找不到有效的回复.

我从模板 [GetData() 和 GetDataUsingDataContract() 附带] 创建了默认的 WCF 服务.
它在浏览器中运行良好.

我有一个单独的网站,我在其中添加了这个新的 WCF 服务:

我执行添加服务引用",输入我的 URL,服务出现,然后我单击确定"添加它.
在App_WebReferences"下,我看到了我添加的服务的命名空间:ServiceReference1",其下有References.svcmap",其下还有几个 .svcinfo/.wsdl/.xsd 文件.

没有创建代理文件,但 元素被添加到我的 web.config 中,其中包含一些似乎是正确的信息.

但是,在没有代理的情况下,我无法访问/调用我的服务中的任何方法(即 ServiceReference1.WCFMethod1())

我可以调用 svcutil,生成代理,将其添加到我的 App_Code 中,然后一切正常.
我的问题是,为什么我的代理不是使用添加服务引用"创建的?
一切都在目标框架下:.NET Framework 4.

刚刚创建了一个控制台应用程序并添加了服务引用并创建了代理.所以问题是我的网站没有创建代理...

解决方案

我遇到了同样的问题,发现取消选中在所有引用的程序集中重用类型确实解决了问题.但是,就我而言,我需要它来重用一些引用库中的类型.我找到了这篇文章,涵盖了一个非常相似的问题.在该帖子中,它引用了一篇 Microsoft 知识库文章,其中描述了针对以下问题的修复:

<块引用>

考虑以下场景:

  • 您在 Visual Studio 2012 中创建了一个 ASP.NET MVC4 Web API 项目.
  • 您在项目中添加 WCF 服务引用.

在这种情况下,服务引用的 Reference.cs 文件是空的.

原因

出现此问题是因为 DataContractSerializer 类遇到了它不支持的类型 (Newtonsoft.Json.Linq.JToken).在这种情况下,它会抛出异常,然后停止生成服务引用.

我没有引用那个 JSON 库,但是,根据那个错误描述,我推测我引用的库之一肯定有类似的问题.我认为我引用的其中一个库可能包含 DataContractSerializer 不支持的类型,它抛出了相同类型的异常,因此以相同的方式失败.

果然,我发现,就我而言,罪魁祸首是我自己的库之一,该库碰巧包含相同 WCF 服务的公共代理.我怀疑是公共代理造成了麻烦.在任何情况下,通过选择在指定的引用程序集中重用类型,然后选择所有程序集除了那个程序集,服务引用会自动正确生成代理类.>

I understand there are other similar questions, but I haven't been able to find a working response.

I create the default WCF service from the template [which comes with GetData() and GetDataUsingDataContract()].
It runs fine in the browser.

I have a separate web site to which I add this new WCF service:

I do 'Add Service Reference', enter my URL, the service comes up and I click 'OK' to add it.
Under 'App_WebReferences', I see the namespace of my added service: 'ServiceReference1', with 'References.svcmap' under it, and a couple .svcinfo/.wsdl/.xsd files under that.

No proxy files are created, but <system.serviceModel> element is added to my web.config, with what seems to be proper information.

However, with no proxy, I can't access/call any methods in my service (ie ServiceReference1.WCFMethod1())

I can call svcutil, generate the proxy, add it to my App_Code, and everything works as it should.
My question is, why isn't my proxy being created with 'Add Service Reference'?
Everything is under target framework: .NET Framework 4.

EDIT:

Just created a Console App and added the service reference and it created the proxy. So the issue is my web site is not creating the proxy...

解决方案

I had this same problem and found that unchecking Reuse types in all referenced assemblies did solve the problem. However, in my case, I needed it to reuse types from some of my referenced libraries. I found this post, covering a very similar problem. In that post, it references a Microsoft knowledge-base article which describes a fix for the the following issue:

Consider the following scenario:

  • You create an ASP.NET MVC4 Web API project in Visual Studio 2012.
  • You add a WCF service reference in the project.

In this scenario, the Reference.cs file for the service reference is empty.

Cause

This issue occurs because the DataContractSerializer class has encountered a type (Newtonsoft.Json.Linq.JToken) that it does not support. In this case, it throws an exception, and then stops generating the service reference.

I wasn't referencing that JSON library, but, based on that bug description, I surmised that one of my referenced libraries must have had a similar problem. I figured that one of the libraries that I was referencing probably contained a type that was not supported by the DataContractSerializer, it was throwing the same kind of exception, and it was therefore failing in the same way.

Sure enough, I found out that, in my case, the culprit was one of my own libraries which happened to include a public proxy for the same WCF service. I suspect it was that public proxy that was causing the trouble. In any case, by selecting Reuse types in specified referenced assemblies, and then selecting all of the assemblies except that one, the service reference automatically generated the proxy classes correctly.

这篇关于添加服务引用不生成代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆