【问题标题】:Getting 'No code was generated' error when trying to create web service proxy using SVCUTIL.EXE尝试使用 SVCUTIL.EXE 创建 Web 服务代理时出现“未生成代码”错误
【发布时间】:2010-09-17 11:50:11
【问题描述】:

当尝试使用 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.

【问题讨论】:

    标签: wcf wcf-client


    【解决方案1】:

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

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

     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!.

    【讨论】:

    • 你的回答不只是解释Warning: No code was generated.吗?这如何解决您遇到的错误?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多