wcf - 如何修复 SvcUtil 为 C++/CLI WCF 客户端生成错误的代码?

标签 wcf c++-cli managed-c++ svcutil.exe

在 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'

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

最佳答案

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

帖子的相关部分是

You should use the following workaround to get a successful compile: Locate the full runtime assembly in: %SysRoot%\Microsoft.NET\Framework\v4.0.30319\System.ServiceModel.dll

Copy this dll.

Replace the Reference Assembly in: %ProgramFiles(x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.ServiceModel.dll

Recompiling your project should now succeed.

关于wcf - 如何修复 SvcUtil 为 C++/CLI WCF 客户端生成错误的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4102764/

相关文章:

托管 C++ 中的 C# 方法

c# - 使用托管 C++ 项目中的 C# 类

c# - 使用 IsOneWay 属性的 WCF 问题

wcf - gRPC和WCF有什么区别?

enums - 显示对象中的位

properties - 如何在 C++/CLI 接口(interface)中声明默认索引属性

winforms - 从进程重定向 StandardOutput

.net - 如何在 C++ 中将 std::string 转换为 CV::String?

c# - 动态装配解析/管理

WCF - 通过 HTTPS 使用 SOAP 服务 - 请求超时