4

在 C++/CLI 中生成 WCF 客户端时,我遇到了由 SvcUtil 生成的代码的问题。

当我运行“SvcUtil.exe /t:code /l:cpp http://localhost:2772/mex/ ”时,它会生成一个包含下面客户端类的头文件。

[System::Diagnostics::DebuggerStepThroughAttribute, 
System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.ServiceModel", L"3.0.0.0")]
public ref class DemoClient : public System::ServiceModel::ClientBase<IDemo^ >, public IDemo
{

    public: DemoClient();
    public: DemoClient(System::String^  endpointConfigurationName);
    public: DemoClient(System::String^  endpointConfigurationName, System::String^  remoteAddress);
    public: DemoClient(System::String^  endpointConfigurationName, System::ServiceModel::EndpointAddress^  remoteAddress);
    public: DemoClient(System::ServiceModel::Channels::Binding^  binding, System::ServiceModel::EndpointAddress^  remoteAddress);
    public: virtual System::String^  GetDemoString() sealed;
};

这会导致很多错误,考虑到它是生成的代码,我不会想到这些错误。

Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Closed::add(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Closed::add'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Closed::remove(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Closed::remove'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Closing::add(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Closing::add'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Closing::remove(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Closing::remove'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Faulted::add(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Faulted::add'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Faulted::remove(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Faulted::remove'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Opened::add(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Opened::add'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Opened::remove(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Opened::remove'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Opening::add(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Opening::add'
Demo.h(41): error C3766: 'DemoClient' must provide an implementation for the interface method 'void System::ServiceModel::ICommunicationObject::Opening::remove(System::EventHandler ^)' : see declaration of 'System::ServiceModel::ICommunicationObject::Opening::remove'

关于我需要更改或添加以纠正此问题的任何建议?我应该只为列出的接口方法添加一个实现吗?

4

2 回答 2

4

由于链接已损坏,您可以使用Wayback Machine查看页面

帖子的相关部分是

您应该使用以下解决方法来获得成功的编译: 找到完整的运行时程序集:%SysRoot%\Microsoft.NET\Framework\v4.0.30319\System.ServiceModel.dll

复制这个dll。

替换参考程序集:%ProgramFiles(x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.ServiceModel.dll

重新编译您的项目现在应该成功了。

于 2018-03-22T07:57:09.973 回答
0

或者,只需在 .vcxproj 中添加所需的 TargetFrameworkVersion

示例:编辑您的 .vcxproj 以在 Globals 范围内的 PropertyGroup 中添加包含 v4.7.2 的 TargetFrameworkVersion 标记

这应该可以在不手动复制任何 dll 的情况下工作。

于 2022-03-02T20:09:55.793 回答