我在C++/CLI dll项目(VS2012 Express)中引用System :: ServiceModel。以下代码失败,出现以下错误,我找不到如何修复它。未找到ServiceMetadataBehavior属性WCF C++/CLI
错误C2337:“的ServiceMetadataBehavior”:属性未找到
[System::ServiceModel::ServiceContractAttribute]
[System::ServiceModel::Description::ServiceMetadataBehavior]
public ref class PlaybackManager
{
public:
~PlaybackManager() { this->!PlaybackManager(); }
!PlaybackManager() { }
// Playback action methods
[System::ServiceModel::OperationContractAttribute]
void Play();
[System::ServiceModel::OperationContractAttribute]
void Stop();
[System::ServiceModel::OperationContractAttribute]
void Pause();
[System::ServiceModel::OperationContractAttribute]
void Previous();
[System::ServiceModel::OperationContractAttribute]
void Next();
[System::ServiceModel::OperationContractAttribute]
void Random();
};
EDIT1:
需要说明的情况是,这是不可能的代码,即完全写的WCF服务没有一个应用程序.config文件。虽然Service具有ServiceMetadataBehavior帮助器来创建元数据交换行为实现,但Endpoint没有这样的事情。这是“按设计”吗? How to: Publish Metadata for a Service Using Code
EDIT2:
OK,所以需要注意上面似乎没有要,一定是正确的。下面是代码中我想要做的事情的app.config,如果我将ServiceMetatdataBehavior属性移除到端点类实现中,我会得到相同的错误。
<configuration>
<system.serviceModel>
<services>
<service name="Engine.PlaybackManager">
<endpoint
address="net.tcp://localhost:7008/PlaybackManager"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
<endpoint
address="net.tcp://localhost:7008/PlaybackManager"
binding="netTcpBinding"
contract="Engine.PlaybackManager"
/>
</service>
</services>
</system.serviceModel>
</configuration>
的错误是:
合同名称“IMetadataExchange接口”无法通过该服务PlaybackManager执行合同的名单 被发现。直接向配置文件或 ServiceHost添加 ServiceMetadataBehavior以启用对此合同的支持。
问题是,如果我将ServiceMetadataBehavior属性添加到PlaybackManager类,我得到上面的原始错误,它不被识别。有任何想法吗?