服务引用错误:无法生成服务引用的代码

发布于 2024-09-28 03:26:56 字数 2469 浏览 1 评论 0原文

我有一个 Windows 服务解决方案,并尝试在 VS2010 中添加对 Hermes(开源 ebms 消息服务器)Web 服务的服务引用。

我可以使用它的 URL 找到 Web 服务,但是当我尝试填充服务引用时,我在 Visual Studio 中收到以下错误:

Error 8 Custom tool error: Failed to generate code for the service reference 'testService'.  Please check other error and warning messages for details. C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler


Warning 6 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://service.ebms.edi.cecid.hku.hk/']/wsdl:portType[@name='EbmsStatusQuery']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:binding[@name='EbmsSoapHttpStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

Warning 7 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:binding[@name='EbmsSoapHttpStatusQuery']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:service[@name='EbmsMessageStatusQuery']/wsdl:port[@name='EbmsStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

Warning 5 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'http://service.ebms.edi.cecid.hku.hk/' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:portType[@name='EbmsStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

一些调查似乎表明这是由于 svcutil.exe 无法构建代理,因为具有目录权限(可能是 c:\windows\temp)。我尝试分配各种访问权限,但我不确定哪个用户需要该权限,或者这是否只是转移注意力。

任何想法将不胜感激。

谢谢

I have a Windows Service Solution and am trying to add a service reference to a Hermes(Opensource ebms message server) Web Service in VS2010.

I can find the Web Service using it's URL, but when I try and populate the Service reference I get the following errors in Visual Studio:

Error 8 Custom tool error: Failed to generate code for the service reference 'testService'.  Please check other error and warning messages for details. C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler


Warning 6 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://service.ebms.edi.cecid.hku.hk/']/wsdl:portType[@name='EbmsStatusQuery']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:binding[@name='EbmsSoapHttpStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

Warning 7 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:binding[@name='EbmsSoapHttpStatusQuery']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:service[@name='EbmsMessageStatusQuery']/wsdl:port[@name='EbmsStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

Warning 5 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'http://service.ebms.edi.cecid.hku.hk/' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:portType[@name='EbmsStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

Some investigation seemed to suggest it is due to svcutil.exe not been able to build the proxys due to not having permissions to a directory (possibly c:\windows\temp). I have tried assigning various access permissions, but I am not really sure which user needs the permission, or if it is just a red herring.

Any ideas would be greatly appreciated.

Thanks

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

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

发布评论

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

评论(13

半边脸i 2024-10-05 03:26:56

必须从配置服务引用选项中取消选中所有引用程序集中的重用类型

查看详细信息

Have to uncheck the Reuse types in all referenced assemblies from Configure service reference option

Check this for details

自由范儿 2024-10-05 03:26:56

右键单击您的服务引用并选择配置服务引用...

配置服务引用

然后取消选中重用引用程序集中的类型

Reuse Types

单击确定,清理并删除重建您的解决方案。

Right click on your service reference and choose Configure Service Reference...

Configure Service Reference

Then uncheck Reuse types in referenced assemblies

Reuse Types

Click OK, clean and rebuild your solution.

辞取 2024-10-05 03:26:56

当尝试使用 Visual Studio 2012 从 ASP .Net MVC 4.0 项目生成 Web 服务的客户端时,我也遇到了类似的错误。

问题的根源似乎是我尝试生成的项目客户端正在引用一个程序集,而该程序集又依赖于另一个也没有被引用的程序集。

当在服务配置中启用“重用引用程序集中的类型”时,服务生成器可能会检查所有引用的程序集以获取可重用的类型列表。所引用的程序集之一正在引用另一个不可用的程序集这一事实可能会导致生成器失败。

从服务配置中取消选中“重用引用程序集中的类型”将解决上述问题,但它会产生副作用。 重用类型选项的存在是有原因的,在某些情况下,它可以避免在使用服务的代码中进行不必要的转换。

例如,如果服务本身是使用 WCF 构建的,并且其中的某些方法参数的类型为 System.Guid,则如果禁用重用类型选项,它们将在生成的客户端中转换为字符串。

我更喜欢禁用重用类型的替代方法是添加专门为此目的创建的类库项目中的服务引用。需要记住的一件事是将所有与服务相关的配置从类库的 app.config 复制到启动项目的配置文件中。

如果本地程序集中定义了需要在服务客户端中重用的类型,则只需从上述类库项目中引用这些程序集及其所有依赖项即可。

I also encountered a similar error when trying to generate the client for a web service from an ASP .Net MVC 4.0 project using Visual Studio 2012.

The root of the problem seems to be that fact that the project from where I was trying to generate the client was referencing an assembly which in turn was dependent on another assembly that was not being referenced as well.

When "Reuse types in referenced assemblies" is enabled in the service configuration, the service generator is probably inspecting all the referenced assemblies to get a list of types that can be reused. The fact that one of the referenced assemblies is referencing another assembly which is not available is probably causing the generator to fail.

Unchecking "Reuse types in referenced assemblies" from the service configurations will solve the above problem, but there is a side effect to it. The reuse types option is there for a reason and in some cases it avoids unnecessary casting in the code consuming the service.

For example, if the service itself is built using WCF and some methods parameters inside it are of type System.Guid, they will be translated to strings in the generated client if the reuse types option is disabled.

An alternative that I prefer to disabling reusing types is to add the service reference from Class Library project specifically created for that purpose. The one thing to keep in mind is to copy all the service related configurations from the class library's app.config to the configuration file of the startup project.

If there are types defined in local assemblies that need to be reused in the service client, those assemblies simply need to be referenced from the above mentioned class library project, along with all their dependencies.

浪荡不羁 2024-10-05 03:26:56

http://uliasz.com/2011/06/wcf-custom-tool-error-failed-to-generate-code-for-the-service-reference/#comment-1647

感谢这篇文章多于。

就我而言,我在 VS.Net 2008 中的 WPF 项目遇到了这个问题。阅读完本文后,我意识到 Web 服务中使用的程序集与客户端上使用的程序集版本不同。

更新客户端上的程序集后,它工作得很好。

http://uliasz.com/2011/06/wcf-custom-tool-error-failed-to-generate-code-for-the-service-reference/#comment-1647

Thanks to the article above.

In my case, i have this issue with my WPF project in VS.Net 2008. After going through this article, i was realizing that the assembly used in the web service is different version of assembly used on client.

It works just fine after updating the assembly on the client.

就像说晚安 2024-10-05 03:26:56

猜测问题极其困难,因为它是由于 WSDL 中的错误造成的,并且在不检查 WSDL 的情况下,我无法发表更多评论。因此,如果您可以共享您的 WSDL,请这样做。

我只能说,WSDL 中似乎缺少架构(目标命名空间为“http://service.ebms.edi.cecid”)。 hku.hk/').我知道忽略包含指令时架构的问题和不同处理。

一般来说,我发现 Microsoft 的 Web 服务实现非常好,因此我认为 Web 服务正在发送回狡猾的 WSDL。

It would be extremely difficult to guess the problem since it is due to a an error in the WSDL and without examining the WSDL, I cannot comment much more. So if you can share your WSDL, please do so.

All I can say is that there seems to be a missing schema in the WSDL (with the target namespace 'http://service.ebms.edi.cecid.hku.hk/'). I know about issues and different handling of the schema when include instructions are ignored.

Generally I have found Microsoft's implementation of web services pretty good so I think the web service is sending back dodgy WSDL.

伤痕我心 2024-10-05 03:26:56

重新启动 Visual Studio 就成功了。我用的是VS 2015。

Restarting Visual Studio did the trick for me. I am using VS 2015.

顾挽 2024-10-05 03:26:56

我在 Silverlight 5 (VS2012) 中遇到相同的错误

您还可以删除对以下内容的引用:

  • System.ServiceModel.DomainServices.Client
  • System.ServiceModel.DomainServices.Client.Web

更新服务引用后,请务必将它们添加回来在。

I get the same error in Silverlight 5 (VS2012)

You can also remove the references to:

  • System.ServiceModel.DomainServices.Client
  • System.ServiceModel.DomainServices.Client.Web

After you've updated the service references, be sure to add them back in.

初心未许 2024-10-05 03:26:56

如上所述,可能存在几个不同的问题。我们发现 WCF 库的 .DLL 已添加为客户端项目的引用。这反过来又在解析对象时产生了问题,从而导致文件被代码生成步骤“清空”。虽然取消选中使用“重用类型...”似乎是一个答案,但它会在新的名称空间中创建对象类型的额外定义,这些对象类型是真实类型的代理,这会导致各种“兼容性”问题这些类型的使用。仅当您确实想“隐藏”类型时才应选中此选项。

当您不希望“DLL”类型依赖项“泄漏”到您试图与另一个项目隔离的项目中时,隐藏类型是合适的。如果 WCF 库项目的 DLL 渗透到客户端项目引用中,那么您将遇到带有各种奇怪副作用的问题,因为类型定义也在 DLL 中。

As stated above, there are a couple of different problems possible. What we found is that the .DLL for the WCF library had been added as a reference to the client project. This, in turn, created problems with resolving the objects and thus caused the files to be "emptied" by code generation steps. While unchecking the use "Reuse Types..." can seem like an answer, it creates extra definitions of object types, which are proxies to the real types, in a new name space, which then causes all kinds of "compatibility" issues with the use of those types. Only if you really want to "hide" a type should you check this option.

Hiding the type would be appropriate when you don't want a "DLL" type dependency to "leak" into a project that you are trying to keep segregated from another. If the DLL for the WCF library project creeps into the client project references, then you will have this problem with all kinds of strange side effects since the type definitions are also in the DLL.

揽月 2024-10-05 03:26:56

遇到同样的问题,通过在管理模式下运行 Visual Studio 解决

face same issue, resolved by running Visual Studio in Admin mode

沫尐诺 2024-10-05 03:26:56

我在在 VS2015 Professional 中升级 VS2010 WCF+Silverlight 解决方案时遇到了这个问题。除了从 Silverlight 4 自动升级到 Silverlight 5 之外,服务引用重用复选框值已更改且生成失败。

I have encountered this problem when upgrading a VS2010 WCF+Silverlight solution in VS2015 Professional. Besides automatically upgrading from Silverlight 4 to Silverlight 5, the service reference reuse checkbox value was changed and generation failed.

停滞 2024-10-05 03:26:56

发生此错误时,“重用类型”并不总是问题。

添加对旧服务的引用时,单击“高级”,然后单击“添加 Web 引用”。现在链接到您的 wsdl,一切都应该可以正常工作。

"Reuse types" is not always the problem when this error occurs.

When adding a reference to an older service, click 'advanced' and there 'Add Web Reference'. Now link to your wsdl and everything should be working.

太阳公公是暖光 2024-10-05 03:26:56

如果您想在不取消选中程序集重用复选框的情况下纠正此问题,这对我有用:

  • 删除要重用的引用程序
  • 集删除项目的所有 bin 文件夹
  • 更新服务引用
    • 保留“重用指定引用程序集中的类型”
  • 再次添加对程序集的引用以修复错误
  • 再次更新服务引用

If you want to correct this without uncheking the assembly reuse checkbox this is what worked for me:

  • Remove referenced assembly that you want to re-use
  • Delete all the bin folder of the project
  • Update service reference
    • Keep "Reuse types in specified referenced assemblies"
  • Add reference to assembly again to fix the errors
  • Update service reference again
梓梦 2024-10-05 03:26:56

我在尝试更新服务引用时遇到了此问题(尽管该错误仅在添加服务引用时显示),但不想删除程序集重用复选框。

对我有用的方法如下:

  • 删除我想重用的引用程序集
  • 更新服务引用
  • 保留“重用指定引用程序集中的类型”
  • 忽略错误,这是因为缺少引用!
  • 再次添加对程序集的引用以修复错误
  • 再次更新服务引用

瞧,现在它实际上更新并且不再尝试删除我生成的所有代码。

我几乎准备放弃重用类型功能...

编辑:还要确保构建配置是 AnyCPU 或 x86,因为 svcutil 在 x64 上有问题。

致反对者:抱歉,如果它对你不起作用,我什至不知道为什么它对我有用,但它确实有效。当时我可能做了其他事情来解决问题,但现在无法知道。

I had this problem when trying to update my service reference (The error only shows up when adding a service reference though) but didn't want to remove the assembly reuse checkbox.

What worked for me was the following:

  • Remove referenced assembly that I wanted to re-use
  • Update service reference
  • Keep "Reuse types in specified referenced assemblies"
  • Ignore the errors, it's because the reference is missing!
  • Add reference to assembly again to fix the errors
  • Update service reference again

Voila, now it actually updates and doesn't try to remove all of my generated code anymore.

I was almost ready to give up on the re-use types feature...

EDIT: Also make sure that the build config is AnyCPU or x86, since svcutil is buggy with x64.

To the downvoter: Sorry if it didn't work for you, I don't even know why it worked for me, but it did. I may have done something else that time that fixed the problem, but no way to know now.

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