我正在尝试生成ServiceClient类。
我有2个项目,API和WEB。 API项目包含ClassLibrary和DataContracts / Interface类文件。我有一个拥有SVC文件的网站。 WEB引用了API项目。
当我生成Service Client类时,它们会在API项目中生成
以下是我遇到的问题
我的SvcUtil命令行包含/参考:[API /bin/debug/API.dll的完整位置]。它与API项目的构建输出路径相同。
当我使用该/ Reference运行SvcUtil命令时,生成失败,我看到以下信息的缩减摘要。
Attempting to download metadata from
'http://id.unittest/Services/EchoService.svc?wsdl'
using WS-Metadata Exchange or DISCO.
Error: Cannot import wsdl:binding
Detail: Cannot locate operation IsSubscribed in Contract IEchoService.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']
/wsdl:binding[@name='WSHttpBinding_IEchoService']
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='WSHttpBinding_IEchoService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']
/wsdl:service[@name='EchoService']/wsdl:port[@name='WSHttpBinding_IEchoService']
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.
当我删除/ reference时,生成成功,但生成了方法参数中使用的一组重复的实体类。当我尝试构建我的API项目时,我得到一个错误,即有重复的类名称,我应该将它们更改为部分。所以,不要也不需要那些额外的课程。
希望我提供了足够的信息。感谢。
答案 0 :(得分:2)
解决方案是将以下开关添加到svcutil命令
/serializer:DataContractSerializer /serializable
参考网址:MSDN forum