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

发布于 2024-09-30 21:28:28 字数 3730 浏览 1 评论 0原文

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

关于我需要更改或添加哪些内容来纠正此问题有什么建议吗?我应该只添加列出的接口方法的实现吗?

I've run into a problem with code generated by SvcUtil when generating a WCF client in C++/CLI.

When I run "SvcUtil.exe /t:code /l:cpp http://localhost:2772/mex/" it generates a header file containing the client class below.

[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;
};

This results in a lot of errors, which I would not have expected given it is generated code.

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'

Any suggestions on what I need to change or add to correct this? Should I just add an implementation for the listed interface methods?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心奴独伤 2024-10-07 21:28:28

由于链接已损坏,您可以使用 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

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

Since the link is broken you can use Wayback Machine to see the page

The relevant part from the post is

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.

节枝 2024-10-07 21:28:28

中添加所需的 TargetFrameworkVersion

或者,只需在 .vcxproj示例 :
编辑 .vcxproj 以添加包含 v4.7.2 的 TargetFrameworkVersion 标记
在全局范围内的 PropertyGroup 内

这应该可以工作,而无需手动复制任何 dll。

Alternatively, just add required TargetFrameworkVersion in .vcxproj

example:
edit your .vcxproj to add TargetFrameworkVersion tag containing v4.7.2
within PropertyGroup at Globals scope

This should work without manually copying any dll.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文