简体   繁体   English

Monotouch和WCF:SVCUTIL.EXE和SLSVCUTIL.EXE的区别以及如何避免不支持的通用ChannelFactory?

[英]Monotouch and WCF: difference of SVCUTIL.EXE and SLSVCUTIL.EXE and how to avoid unsupported generic ChannelFactory?

I'm (again and still) trying to consume some WCF services in Monotouch. 我(再次,仍然)尝试在Monotouch中使用一些WCF服务。 First approach: add a web reference in Monodevelop failed. 第一种方法:在Monodevelop中添加Web引用失败。 It cannot create the reference file. 它无法创建参考文件。 Then I tried SVCUTIL.EXE and get an error that the generic ChannelFactory is not available in Monotouch - I suppose because there is no reflection available. 然后我尝试了SVCUTIL.EXE并得到一个错误,通用的ChannelFactory在Monotouch中不可用 - 我想因为没有可用的反射。

Next I tried SLSVCUTIL.EXE from the Silverlight 3 SDK. 接下来,我尝试了Silverlight 3 SDK中的SLSVCUTIL.EXE。 This generates namespaces for the various services that differ from those created through SVCUTIL.EXE. 这会生成与通过SVCUTIL.EXE创建的服务不同的各种服务的命名空间。 As I have already lots of wrapper code I have to change a lot. 由于我已经有很多包装代码,我必须改变很多。

These questions arise: 这些问题出现了:

  • Can I override the CreateChannel methods and return specialized channels for each service instead of being dependent on the non-existing generic version, as proposed by the exception that gets thrown? 我是否可以覆盖CreateChannel方法并返回每个服务的专用通道,而不是依赖于不存在的泛型版本,如抛出的异常所提议的那样? This means fixing the code generated by SVCUTIL.EXE. 这意味着修复SVCUTIL.EXE生成的代码。
  • How do I create a channel in an overridden method? 如何在重写方法中创建通道? I only have interfaces of my services. 我只有我的服务接口。 I googled and could not find any examples. 我用谷歌搜索,找不到任何例子。 What does code look like that has to be written in that method? 代码看起来像什么,必须用该方法编写?
  • Totally unclear to me: what is the difference between the two service utilities? 我完全不清楚:两个服务实用程序之间有什么区别?
  • If I get the namespace issue sorted out, will the stubs created through the Silverlight utility make my project work, or will that also suffer from the generic channel issue? 如果我解决了命名空间问题,那么通过Silverlight实用程序创建的存根是否会使我的项目工作,还是会受到通用通道问题的影响?
  • why can the Silverlight tool work without dynamically emitting code? 为什么Silverlight工具可以在不动态发出代码的情况下工作? What is the difference in the outputted code and what advantage does the dynamic version have? 输出代码有什么区别,动态版有什么优势?
  • which version of Silverlight is supported int MT. MT支持哪个版本的Silverlight。 Can I use the tool of v4 or does it have to be version 3? 我可以使用v4的工具还是必须是版本3?
  • Does WCF in MT support streaming, like downloading large files? MT中的WCF是否支持流式传输,例如下载大型文件?

WCF is a huge beast and it's very difficult to give general answers on it, too much depends on details. WCF是一个巨大的野兽,很难给出一般答案,太多取决于细节。 The general rule is that MonoTouch supports the same subset of WCF that was shipped with Silverlight (even if a few additions were made over time). 一般规则是MonoTouch支持Silverlight附带的相同WCF子集(即使随着时间的推移做了一些添加)。

I suppose because there is no reflection available. 我想因为没有可用的反映。

Reflection is available and works with MonoTouch. 可以使用反射并与MonoTouch配合使用。 Reflection.Emit does not since Apple does not allow JIT'ing code on iOS devices. Reflection.Emit 没有,因为Apple不允许在iOS设备上使用JIT代码。 This can limit some API that requires code generation at runtime (but is not an issue if the code generation can be done at compile time). 这可能会限制某些需要在运行时生成代码的API(但如果代码生成可以在编译时完成,则不会出现问题)。

... This means fixing the code generated by SVCUTIL.EXE. ...这意味着修复SVCUTIL.EXE生成的代码。 ... ...

Fighting/editing generated code is usually a bad idea (eg future maintenance). 战斗/编辑生成的代码通常是一个坏主意(例如,未来的维护)。 I suggest you try to use slsvcutil.exe before investing too much time in customizing the generated code. 我建议您在投入太多时间自定义生成的代码之前尝试使用slsvcutil.exe

... What does code look like that has to be written in that method? ...代码看起来像是必须用该方法编写的?

The full source code for Mono's System.ServiceModel and System.ServiceModel.Web are available if you wish to provide your own channel (or customize the generated code). 如果您希望提供自己的频道(或自定义生成的代码),则可以使用Mono的System.ServiceModelSystem.ServiceModel.Web的完整源代码。

Totally unclear to me: what is the difference between the two service utilities? 我完全不清楚:两个服务实用程序之间有什么区别?

The SL prefix, in slsvcutil.exe , is for Silverlight. slsvcutil.exe中SL前缀适用于Silverlight。 Microsoft made this tool to generate code that will only use the WCF subset available in Silverlight. Microsoft制作此工具以生成仅使用Silverlight中可用的WCF子集的代码。 Since this is the same subset supported by MonoTouch this is the best tool to use. 由于这是MonoTouch支持的相同子集,因此这是最好的工具。

If I get the namespace issue sorted out, will the stubs created through the Silverlight utility make my project work, or will that also suffer from the generic channel issue? 如果我解决了命名空间问题,那么通过Silverlight实用程序创建的存根是否会使我的项目工作,还是会受到通用通道问题的影响?

It should work. 应该工作。 That's how people are using (the available subset of) WCF with MonoTouch today. 这就是人们今天使用MonoTouch的WCF(可用子集)的方式。 If there are issues with this (subset/tool) you can fill a bug report about it (with a test case) and we'll have a look at it. 如果存在此问题(子集/工具),您可以填写有关它的错误报告(带有测试用例),我们将查看它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM