2

I observe strange behavior of SvcUtils.exe.

If I pass there /reference parameter, it does not generate *.cs file for some reason.

C:\test>"C:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe" /t:code http://localhost/Api/Common.svc /r:Api.dll
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.17929]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'http://localhost/Api/Common.svc' using WS-Metadata Exchange or DISCO.
Generating files...
C:\test\output.config

At the same time, if I remove the parameter, it generates it normally.

C:\test>"C:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe" /t:code http://localhost/Api/Common.svc
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.17929]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'http://localhost/Api/Common.svc' using WS-Metadata Exchange or DISCO.
Generating files...
C:\test\CommonService.cs
C:\test\output.config    

Why? How to get the classes from Api.dll that are used in Api.svc to be generated in CommonService.cs?

UPD. Let me add some details that seem to me obvious but nevertheless important. The Api.dll assemply includes classes marked with [DataContract] attribute with properties marked with [DataMember] attribute. These classes are returned from methods visible in Api.svc. My goal is to reuse the classes from Api.dll in generated proxy code.

Why I find this behavior strange? It generates proxy classes normally for services without reuse, but if I add /r parameter to reuse classes, it refuses to generate code at all. So the question is what is done wrong? What could be done wrong to get this behavior and how to do it right to achieve the goal?

UPD2. The most strange is that updating references from Visual Studio with checked "reuse" option works perfectly.

4

1 回答 1

2

我遇到了同样的问题。我实际上使用的是 svcutil,因为 Visual Studio 给了我错误,即无法创建 WCF 引用的代码并且没有提供更多信息。我最终在 VS 中启用了警告,这给了我更多信息。事实证明,我正在引用一个本身引用 WCF 服务的程序集。因此,某些类型被包含两次。然后类型的映射失败。我所做的是配置引用了哪些程序集。因此,我只选择了 WCF 服务,然后选择了标准的 .NET 系统程序集。我还禁用了生成数据合约(我启用它只是为了尝试)并且能够构建。

简而言之:确保您要使用的类型只被引用一次。

于 2013-04-03T12:57:56.637 回答