此 WCF 错误是什么意思:“自定义工具警告:无法导入 wsdl:portType”

发布于 2024-08-14 05:57:15 字数 2158 浏览 3 评论 0原文

我在我的解决方案中创建了一个 WCF 服务库项目,并拥有对此的服务引用。我使用类库中的服务,因此除了类库之外,我还引用了 WPF 应用程序项目中的内容。服务设置直接 - 仅更改以获得异步服务功能。

一切都工作正常 - 直到我想更新我的服务参考。它失败了,所以我最终回滚并重试,但即使这样也失败了!因此,如果不对其进行任何更改,更新服务引用就会失败。为什么?!

我得到的错误是这个:

Custom tool error: Failed to generate code for the service reference 
'MyServiceReference'.  Please check other error and warning messages for details.   

警告提供了更多信息:

Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: 
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: List of referenced types contains more than one type with data contract name 'Patient' in  
namespace 'http://schemas.datacontract.org/2004/07/MyApp.Model'. Need to exclude all but one of the 
following types. Only matching types can be valid references: 
"MyApp.Dashboard.MyServiceReference.Patient, Medski.Dashboard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
"MyApp.Model.Patient, MyApp.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']

还有两个类似的警告也说:

Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_ISomeService']  

相同的是:

Custom tool warning: Cannot import wsdl:port .. 

我发现这一切都很令人困惑.. 我在客户端仪表板上没有 Patient 类,除了一个我通过了服务参考。那么这意味着什么呢?而且为什么会突然出现呢?请记住:我什至没有改变任何东西!

现在,在此处找到了解决方案,但没有解释这意味着什么。所以;在服务的“配置服务引用”中,取消选中“重用引用的程序集中的类型”复选框。现在重建一切正常,没有问题。但我真正改变了什么?这会对我的申请产生影响吗?什么时候应该取消选中此选项?我确实想重用已设置 DataContract 的类型,但仅此而已。如果没有经过此检查,我仍然可以访问那些内容吗?

I created a WCF service library project in my solution, and have service references to this. I use the services from a class library, so I have references from my WPF application project in addition to the class library. Services are set up straight forward - only changed to get async service functions.

Everything was working fine - until I wanted to update my service references. It failed, so I eventually rolled back and retried, but it failed even then! So - updating the service references fails without doing any changes to it. Why?!

The error I get is this one:

Custom tool error: Failed to generate code for the service reference 
'MyServiceReference'.  Please check other error and warning messages for details.   

The warning gives more information:

Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: 
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: List of referenced types contains more than one type with data contract name 'Patient' in  
namespace 'http://schemas.datacontract.org/2004/07/MyApp.Model'. Need to exclude all but one of the 
following types. Only matching types can be valid references: 
"MyApp.Dashboard.MyServiceReference.Patient, Medski.Dashboard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
"MyApp.Model.Patient, MyApp.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']

There are two similar warnings too saying:

Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_ISomeService']  

And the same for:

Custom tool warning: Cannot import wsdl:port .. 

I find this all confusing.. I don't have a Patient class on the client side Dashboard except the one I got through the service reference. So what does it mean? And why does it suddenly show? Remember: I didn't even change anything!

Now, the solution to this was found here, but without an explanation to what this means. So; in the "Configure service reference" for the service I uncheck the "Reuse types in the referenced assemblies" checkbox. Rebuilding now it all works fine without problems. But what did I really change? Will this make an impact on my application? And when should one uncheck this? I do want to reuse the types I've set up DataContract on, but no more. Will I still get access to those without this checked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

风筝有风,海豚有海 2024-08-21 05:57:15

我在这里找到了答案: http ://www.lukepuplet.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html

长话短说:我取消选中在参考程序集中重用类型高级菜单


我不知道这是否重要,但我没有使用 MVC,而是使用 Web 表单。

I found my answer here: http://www.lukepuplett.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html

Long story short: I unchecked Reuse types in reference assemblies from the Advanced menu.


I don't know if this matters but i'm not using MVC, but Web Forms.

野却迷人 2024-08-21 05:57:15

添加服务引用时,可以通过两种方式处理服务使用的类型:

  • 类型存储在 dll 中,并且客户端和服务器应用程序都引用该 dll。
  • 这些类型不在客户端引用的 dll 中。在这种情况下,创建服务引用的工具将在references.cs 文件中创建类型。

有很多事情可能会出错。我们发现,如果工具崩溃,有时删除服务引用并重新启动会更快。

我们已停止使用服务参考。对于我们控制客户端和服务的项目,我们使用中描述的方法截屏视频

When you add a service reference, there are two ways the types that are used by the service can be handled:

  • The types are stored in a dll, and that dll is referenced from both the client and the server application.
  • The types are not in a dll referenced by the client. In that case the tool that creates the service reference, will create the types in the references.cs file.

There are many things that can go wrong. We have found that if the tool crashes, it is sometimes faster to delete the service reference and start again.

We have stopped using service reference. For projects where we have control of the client and the service, we use the method described in this screencast.

冷清清 2024-08-21 05:57:15

我今天也遇到这个问题了。我花了一整天的时间才发现我的错误。希望有帮助。

我无法导入的类具有自定义枚举类型属性。此属性标记为 DataMember,并且 Enum 也标记为 DataContract。到目前为止一切都很好。
我只是忘记将每个枚举成员标记为 EnumMember。

所以我改成了

[DataContract]
public enum SortMethodType
{
    Default = 0,
    Popularity = 1,
    ReleaseDate = 2,
    PublishedDate = 3,
    TranslatedTitle = 4,
    OriginalTitle = 5,
    UserRating = 6,
    Duration = 7
}

这样:

[DataContract]
public enum SortMethodType
{
    [EnumMember]
    Default = 0,
    [EnumMember]
    Popularity = 1,
    [EnumMember]
    ReleaseDate = 2,
    [EnumMember]
    PublishedDate = 3,
    [EnumMember]
    TranslatedTitle = 4,
    [EnumMember]
    OriginalTitle = 5,
    [EnumMember]
    UserRating = 6,
    [EnumMember]
    Duration = 7
}

终于成功了!

I also had this issue Today. It took me one entire day to find my mistake. Hope it helps.

My class that weren't able to be imported has a cutom enum type property. This property is marked as DataMember and the Enum is also marked as DataContract. Everything fine so far.
I just forgot to mark every enum member as EnumMember.

So i changed

[DataContract]
public enum SortMethodType
{
    Default = 0,
    Popularity = 1,
    ReleaseDate = 2,
    PublishedDate = 3,
    TranslatedTitle = 4,
    OriginalTitle = 5,
    UserRating = 6,
    Duration = 7
}

To this:

[DataContract]
public enum SortMethodType
{
    [EnumMember]
    Default = 0,
    [EnumMember]
    Popularity = 1,
    [EnumMember]
    ReleaseDate = 2,
    [EnumMember]
    PublishedDate = 3,
    [EnumMember]
    TranslatedTitle = 4,
    [EnumMember]
    OriginalTitle = 5,
    [EnumMember]
    UserRating = 6,
    [EnumMember]
    Duration = 7
}

And it finally worked!

战皆罪 2024-08-21 05:57:15

添加引用时转到高级属性并从清单中删除“System.Window.Browser”,它解决了问题。

Go to Advanced properties while adding reference and remove "System.Window.Browser" from the checklist, It solves the problem.

挽清梦 2024-08-21 05:57:15

这可能听起来很奇怪,但我通过删除引用,然后关闭 Visual Studio,然后再次重新打开它,最后再次添加引用来修复它。

我认为自定义工具需要重新启动或其他东西。

that might sound weird, but I got it fixed by deleting the references, then closing Visual Studio, and reopening it again, and finally adding the references again.

I think the custom tool thing needed to be restarted or something.

梦萦几度 2024-08-21 05:57:15

当它在另一台开发人员机器上运行时,我经常遇到此错误。尽管我在虚拟机中的任何地方都是完全管理员,但我尝试关闭 Visual Studio,然后使用“以管理员身份运行”重新打开,它神奇地工作了。

祝你好运。

I constantly run across this error while it works on another developers machine. Even though I'm a full admin everywhere in my virtual machine, I tried closing Visual Studio, and re-opening with 'Run As Administrator' and it magically worked.

Good luck.

牵你手 2024-08-21 05:57:15

将解决方案从 Visual Studio (VS) 2010 升级到 2013 并将每个项目的 .NET Framework 从 4 更改为 4.5.1 后,我收到了警告。我关闭 VS 并重新打开,警告就消失了。

I got the warning after upgrading my solution from Visual Studio (VS) 2010 to 2013 and changing each project's .NET Framework from 4 to 4.5.1. I closed VS and re-opened and the warnings went away.

許願樹丅啲祈禱 2024-08-21 05:57:15

关闭“引用程序集中的重用类型”的一个缺点是,它可能会导致引用不明确的问题。这是因为服务引用在引用 .cs 文件中再次创建这些对象,并且实现该服务的代码可能从原始命名空间引用它们。

发生这种情况时,我发现检查“指定引用的程序集中的重用类型”很有用,它允许我仅选择具有不明确引用的程序集,这样可以快速解决问题。

希望它对其他人有帮助。

One downside of turning off 'reuse types in referenced assemblies' is that it can cause issues with ambiguous references. This is due to the service reference creating those objects again in the reference .cs file, and your code implementing the service may be referencing them from the original namespace.

When this scenario occurs I find it useful to check the 'reuse types in specified referenced assemblies' which allows me to choose the ones with ambiguous references only, which resolves the issue quickly that way.

Hope it helps someone else.

颜漓半夏 2024-08-21 05:57:15

我的 WCF 服务接口位于一个程序集中,实现位于另一个程序集中,服务引用位于另一个程序集中,与服务引用的客户端分开。在将 DataContract 应用于枚举后,我立即收到了错误消息。当我将 EnumMember 应用到枚举的字段后,问题就解决了。

My interfaces of the WCF service are in an assembly, the implementation is in an another and the service reference is in yet another assembly, separate from the clients of the service reference. I got the error message right after I applied the DataContract to an enum. After I applied EnumMember to the fields of the enum, the issue resolved.

嘦怹 2024-08-21 05:57:15

如果怀疑您的服务没有任何问题(例如枚举问题或其他人提到的不可序列化类),请尝试使用新引用创建一个新项目

我正在使用 Silverlight 5,并且曾多次尝试删除并重新创建引用。 reference.cs 文件每次都完全是空的,而且自从我创建它以来已经过去了很多年,所以试图找出服务中发生了什么变化是不可能的。

我注意到该错误包含对 2.0.5.0 的引用。现在我什至不知道这是否真的与 Silverlight 版本相关,但这让我想到创建一个全新的项目,然后突然一切都正常了。

警告 2 自定义工具警告:无法导入 wsdl:portType 详细信息:An
运行 WSDL 导入扩展时引发异常:
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
错误:无法加载文件或程序集“System.Xml,版本=2.0.5.0,
Culture=neutral, PublicKeyToken=7cec85d7bea7798e' 或其之一
依赖关系。系统找不到指定的文件。 X 路径到
错误来源: //wsdl:definitions[@targetNamespace='']/wsdl:port
输入[@name='IShoppingCart']

If in doubt that your service doesn't have any problems (such as problems with enums, or non-serializable classes as mentioned by others) then try to create a new project with a new reference.

I am using Silverlight 5 and I had tried to delete and recreate the reference several times. The reference.cs file just came up completely empty each time and it had been literally years since I'd created it so trying to figure out what had changed in the service was out of the question.

I noticed that the error contained references to 2.0.5.0. Now I don't even know if this is actually relevant to the Silverlight version, but it made me think of just creating a brand new project and then suddenly everything worked.

Warning 2 Custom tool warning: Cannot import wsdl:portType Detail: An
exception was thrown while running a WSDL import extension:
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Could not load file or assembly 'System.Xml, Version=2.0.5.0,
Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its
dependencies. The system cannot find the file specified. XPath to
Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:port
Type[@name='IShoppingCart']

遗失的美好 2024-08-21 05:57:15

我正在查看我的项目,也遇到了同样的问题。事实证明,WCF 与网站上的同一个 DLL 的不同版本。
网站有较新版本的 DLL,而服务正在引用较旧版本的 DLL。一旦它们全部同步,一切都运行良好。

I was looking over my project and I was having this same issue. It turned out to be different versions of the same DLL on the WCF vs. Web Site.
Web site had a newer version of the DLL and the service was referencing an older version of the DLL. Once they were all in sync all worked well.

初懵 2024-08-21 05:57:15

我遇到了同样的错误。我挣扎了将近一天,试图找出问题所在。对我来说,线索是 VS 发出的警告。它试图对 Yahoo.Yui.Compressor.dll 进行某种映射,这是我几天前添加和删除的一个库(因为我决定不使用它)。这是令人震惊的,因为图书馆不在那里,但不知何故它试图引用它。

最后,我从垃圾箱中恢复了这个 dll,然后我就可以成功更新我的服务引用了。

I experienced the same error. I struggled for almost a day trying to find out what was going wrong. The clue for me were the warnings that VS was throwing. It was trying to do some kind of mapping to Yahoo.Yui.Compressor.dll, a library I had added and removed (because I decided not to use it) a couple of days before. It was shocking because the library wasn't there, but somehow it was trying to reference it.

Finally, I restore this dll from the Trash, and then I could update my service reference successfully.

缱绻入梦 2024-08-21 05:57:15

对于将来的任何人来说,我都会遇到同样的错误,但由版本问题引起,以两种不同的方式。

我有两个 WCF 服务和两个通过服务引用进行通信的客户端应用程序。我更新了双方的 nuget 包并尝试更新服务引用并收到此错误。

删除并没有帮助。取消选中“重用程序集”是不需要的,因为我需要重用它们 - 这就是重点。

最后,出现了两个独立的问题:

1)我认为第一个问题是视觉工作室缓存问题。我仔细检查了所有参考资料,没有发现任何问题,但仍然报告无法找到该文件的先前版本。我卸载了所有 nuget 软件包,重新启动 Visual Studio,然后重新安装它们。更新服务参考有效。

2)第二个问题是由依赖问题引起的。我更新了双方的 nuget 包,一切看起来都正确,但未标记的依赖项不同步。示例:

包 Foo v1 引用 Bar v1。
可以将 Foo 和 Bar 独立更新到 v2,而无需更新引用。
如果您同时安装 Foo 和 Bar v2,服务引用工具将扫描 Foo v2,查看对 Bar v1 的引用,然后失败,因为它找不到旧版本。
仅当您更新每个包的 dll 版本号时,才会正确报告此情况。
Visual Studio 和 MSBuild 构建应用程序不会有任何问题,但服务引用在尝试解决所有问题时会遇到困难。

我希望这对某人有帮助。

For anyone here in the future, I had the same error but caused by version issues, in two different ways.

I have two WCF services and two client applications that talk via the service references. I updated a nuget package on both sides and tried to update the service reference and got this error.

Deleting didn't help. Unchecking "reuse assemblies" is not desired as I need to reuse them - that's the whole point.

In the end, there were two separate issues:

1) The first issue, I believe, was a visual studio caching issue. I meticulously went over all of the references and found no issues but it still reported being unable to find the previous version of the file. I uninstalled all of the nuget packages, restarted visual studio, and reinstalled them. Updating the service reference worked.

2) The second issue was caused by a dependency issue. I updated the nuget package on both sides and everything appeared correct, but an unmarked dependency was out of sync. Example:

Package Foo v1 references Bar v1.
It is possible to update Foo and Bar to v2 independently without updating the reference.
If you install both Foo and Bar v2 the service reference tool will scan Foo v2, see the reference to Bar v1, and fail because it can't find the older version.
This is only reported correctly if you update the version numbers of your dll for every package.
Visual Studio and MSBuild will have no problem building the application but the service reference will have a terrible time trying to resolve everything.

I hope this helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文