如何为 RESTful WCF 实现自定义 QueryStringConverter?
我已经实现了一个自定义的 QueryStringConverter 类,并使用自定义的 WebHttpBehavior 子类将其连接起来。当我进行服务调用时,它会命中 CanConvert 覆盖中的断点(并且我为此参数返回 true),但它从未调用我的 ConvertStringToValue 覆盖,并且最终只是将 null 传递给服务调用...为什么 ConvertStringToValue 永远不会打电话,我该如何解决?
I've implemented a customized QueryStringConverter class and hooked it up using a customized WebHttpBehavior subclass. When I make a service call, it hits my breakpoint in the CanConvert override (and I return true for this parameter), but it never calls my ConvertStringToValue override, and ends up just passing null to the service call... why is ConvertStringToValue never called and how can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是不可能的。
Microsoft 对该功能的实现非常草率,以至于他们只是更新了标准 QueryStringConverter,而不是使用配置文件中配置的 QueryStringConverter。
没有任何实际可行的解决方法。错误报告中的第二个实际上根本不起作用。
简短的回答是你不能。
请参阅此处的错误: http://connect.microsoft.com/VisualStudio/feedback/details/616486/bug-with-getquerystringconverter-not-being- Called-by-webservicehost#tabs
它在框架 4.0 中仍然损坏。
我的猜测是这并不重要 - 因此也许需要花时间增加错误的计数。
问候
克雷格。
This is not possible.
Microsoft were so sloppy with the implementation of this functionality that they merely newed up the standard QueryStringConverter instread of using the one configured in the configuration file.
There are no work arounds that actually work. The second one in the bug report doesn't actually work at all.
The short answer is that you cannot.
See the bug here: http://connect.microsoft.com/VisualStudio/feedback/details/616486/bug-with-getquerystringconverter-not-being-called-by-webservicehost#tabs
It is still broken in framework 4.0.
My guess is that it's not important - so perhaps take the time to increase the counts on the bug.
Regards
Craig.
我知道这是一个很老的问题。对于任何寻找答案的人,您应该能够将 TypeConverter 添加到您的类中,该类可以将类型与字符串表示形式相互转换
http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.querystringconverter.aspx
I know it is quite old question. For any one who looking for some answer, you should be able to add the TypeConverter to your class which can convert type to and from string representation
http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.querystringconverter.aspx
做这样的事情:
在合同文件中
在服务文件中
结论:
通过将 Xml 格式数据发送到字符串参数来调用服务。然后将xml转换为所需的类对象。这样你就可以避免创建相当麻烦的QueryStringConvertor。希望这会有所帮助!此帮助适用于所有人,而不仅仅是这篇文章。
Do some thing like this:
In contract file
In the Service file
Conslusion:
Call the service by sending Xml format data to a string parameter. Then convert the xml to the required class object. This way you can avoid creating QueryStringConvertor which is quite cumbersome. Hope this will help! This help is for all and not just for this post.