简体   繁体   English

REST服务-我是否真的必须阅读OperationContext才能获得消息?

[英]REST Services - Do I really have to read the OperationContext to get the message?

I'm trying to create a sample REST-service and a client. 我正在尝试创建一个示例REST服务和一个客户端。 I'm quite shocked, because it seems that I can only ready the messagebody over a hack, the operationContext: 我很震惊,因为似乎我只能通过hack操作上下文来准备消息正文:

var ctx = OperationContext.Current.RequestContext.RequestMessage;

So I can just send primitive types over the URI and have to go over the context to read the xml data? 因此,我可以通过URI发送原始类型,并且必须遍历上下文以读取xml数据? Since it seems I can just select xml or json as body, I have to work with one of these. 由于似乎我只能选择xml或json作为正文,因此我必须使用其中之一。 So all I can pass directly are primitive types over the URI? 因此,我可以直接传递的只是URI上的原始类型?

Which leads me to the question: Is it not the idea of REST to pass complex types but primitives over the URI? 这就引出了一个问题:不是通过REST传递复杂类型而是通过URI传递原语的想法? Or is there a easier solution I didn't find yet? 还是有一个我找不到的更简单的解决方案?

In order to make restful services you should consider using WCF Restful services. 为了提供宁静的服务,您应该考虑使用WCF宁静的服务。 They are easy and Robust. 它们既简单又健壮。 You can see a tutorial here 你可以在这里看到一个教程

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

相关问题 我真的必须创建多个模型吗? - Do I have to really create multiple models? 访问WCF编码器中的传入消息属性(OperationContext.Current为null) - Get access to incoming message properties in WCF encoder (OperationContext.Current is null) 我是否真的必须在自定义控件的OnMouseDown中调用Focus? - Do I really have to call Focus in OnMouseDown of my custom Control? 在XElement中设置值-我真的必须从根开始吗? - Set value in XElement - do I really have to start from the root? 如何模拟OperationContext.Current(WCF消息) - How to mock OperationContext.Current (WCF Message) 我真的必须以不同的方式编写我的代码,以便可以测试它吗? - Do I really have to do write my code differently so just so I can test it? 从WCF OperationContext获取方法参数 - Get method parameters from WCF OperationContext 使用线程时是否需要锁定“只读”服务? - Do I need to lock “read only” services when using threading? 如何获取GetResourceStream来读取扩展名为.txt以外的文件? - How do I get GetResourceStream to read files that have an extension other than .txt? ASP.NET MVC:是否真的必须为每个动作创建一个视图? - ASP.NET MVC: Do I really have to create one view per action?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM