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

Sim*_*ver 2 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.
Run Code Online (Sandbox Code Playgroud)

Sim*_*ver 5

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

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

 svcutil.exe https://dev.example.com/ShoppingCartWS/WCF/ShoppingCartWCF.svc?wsdl
Run Code Online (Sandbox Code Playgroud)

如果您看到任何请求以500(红色)和以下响应返回,则您可能遇到与我相同的问题.

ReadResponse() failed: The server did not return a response for this request.                                                                            
Run Code Online (Sandbox Code Playgroud)

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

这是我找到解决方案的地方 - 非常感谢!.