尝试使用SVCUTIL.EXE创建Web服务代理时出现“未生成代码”错误

时间:2010-09-17 03:20:02

标签: wcf wcf-client

尝试使用SVCUTIL.EXE(在命令行或通过Visual Studio)创建Web服务代理(WCF)时,我得到以下无意义的错误消息。

注意:该服务没有任何问题,因为它可以在另一台机器上正常工作。这是Windows的新安装,该服务在我的本地盒子上。使用不同机器上的URL在我的机器上生成相同的代理工作正常。

发生了什么事??

Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'https://ws1.example.com/ShoppingCartWS/WCF/ShoppingCartWCF.svc?wsdl' using WS-Metadata Exchan
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageCont
Error: Schema with target namespace '' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:portType[@name='IShoppingCart']


Error: 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='']/wsdl:portType[@name='IShoppingCart']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_IShoppingCart']   

.....    

Error: 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='']/wsdl:portType[@name='IShoppingCart']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IShoppingCart1']


Error: 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://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IShoppingCart1']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='ShoppingCartWCF']/wsdl:port[@name='BasicHttpBinding_IShoppingCart1']


Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.

Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.

1 个答案:

答案 0 :(得分:5)

Warning: No code was generated目录上对应用程序池用户缺少权限可以触发此C:\Windows\Temp错误消息(是的!)

如果您收到此错误,我建议您在尝试使用“添加服务引用”对话框时切换到命令行。运行此命令,打开Fiddler作为服务URL。

 svcutil.exe https://dev.example.com/ShoppingCartWS/WCF/ShoppingCartWCF.svc?wsdl

如果您看到任何请求以500(红色)和以下回复的形式返回,那么您可能会遇到与我相同的问题。

ReadResponse() failed: The server did not return a response for this request.                                                                            

只需检查C:\Windows\Temp,然后添加您的应用池正在运行的任何用户即可获得权限。我只是作弊并添加了Everyone,但如果安全性很重要,您应该从IIS中找到正确的应用程序池用户名。

This is where I found the solution - many thanks!

相关问题