本文主要是介绍c++中literal_XML Web Services中的Doc / Literal / Bare-我对此的看法。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
c++中literal
Apparently Craig Andera and Tim Ewald were recently working on an MSDN code rewrite and were talking about building doc/literal/bare Web Services vs. doc/literal/wrapped.
显然,克雷格·安德拉( Craig Andera)和蒂姆·埃瓦尔德( Tim Ewald )最近正在着手进行MSDN代码重写,并在讨论构建doc / literal / bare Web Services与doc / literal / wrapped。
I'm a little confused by their respective posts, as they appear to say too different things. (Coming up on Fox, When Smart People Disagree!) They were both in the same house, coding the same stuff, but Craig's conclusion about how to use SoapParameterStyle.Bare is very different than Tim's (and mine).
我对他们各自的职位有些困惑,因为他们似乎说了太多不同的话。 (出现在Fox上,当聪明人不同意! )他们俩都在同一间屋子里,编码相同的东西,但是Craig关于如何使用SoapParameterStyle.Bare的结论与Tim(和我的)有很大不同。
Tim suggests that getting an AddResponse type "for free" when writing code like this:
蒂姆建议在编写如下代码时“免费”获得AddResponse类型:
//SDH: This is bad, avoid it[WebMethod]
[return: XmlElement("sum")]
public int Add(int x, int y) { return x + y; }
// SDH:这很糟糕,请避免[WebMethod] [返回:XmlElement(“ sum”)] public int Add(int x,int y){return x + y; }
is lame, and I agree. The generared AddResponse type is totally magic, coming (by magic) from the Method name, which is a little too tightly-coupled for my tastes.
la脚,我同意。 通用的AddResponse类型完全是魔术,来自于Method名称(通过魔术),这对我来说有点太紧密了。
Instead, your functions should take as parameters and return as reponses formal types that you control. Then you can use the [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)] attribute to avoid any extra automagically-added wrapped elements. This is purely a coding convention, it's not expressed in WSDL.
相反,您的函数应以参数为参数,并以响应形式返回您控制的形式类型。 然后,可以使用[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]属性来避免任何多余的自动添加的包装元素。 这纯粹是一种编码约定,未在WSDL中表达。
//SDH: This is not bad, embrace it.[WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]
[return: XmlElement("AddResponse")]
public AddResponse Add(AddRequest req)
{
AddResponse resp = new AddResponse();
resp = req.x + req.y;
return resp;
}
// SDH:这还不错,拥抱它。 [WebMethod] [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)] [返回:XmlElement(“ AddResponse”)] 公共AddResponse Add(AddRequest请求) { AddResponse resp =新的AddResponse(); resp = req.x + req.y; 回报}
Tim's right on with this. We do the same thing at Corillian with our code-generation stuff (maybe I'll present on it sometime.) You can reuse the Request and Response messages this way, as well as take and return base classes.
蒂姆对此表示赞同。 在Corillian,我们用代码生成的东西做同样的事情(也许我会在某个时候出现。)您可以通过这种方式重用Request和Response消息,以及获取和返回基类。
However, Craig had a different view. He simply added the bare attribute to the method call:
但是,克雷格有不同的看法。 他只是将裸属性添加到方法调用中:
//SDH: This is bad, think twice
[WebMethod]
[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]
public int Add(int x, int y) { return x + y; }
// SDH:这很糟糕,请三思[WebMethod] [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)] public int Add(int x,int y){return x + y; }
which results in
导致
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<x xmlns="http://tempuri.org/">int</x>
<y xmlns="http://tempuri.org/">int</y>
</soap:Body>
</soap:Envelope>
<?xml版本=“ 1.0”编码=“ utf-8”?> <soap:Envelope xmlns:xsi =“ http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd =“ http://www.w3.org/2001/XMLSchema” xmlns:soap =“ http://schemas.xmlsoap.org/soap/envelope/”> <soap:Body> <x xmlns =“ http://tempuri.org/”> int </ x> <y xmlns =“ http://tempuri.org/”> int </ y> </ soap:Body> </ soap:信封>
Which is a non-WS-I Basic Profile compliant Web Service, as it has more than one child node under <soap:Body>. Craig muses "To me, this just seems like nicer XML; more like how I would do it if I were just using XmlWriter and raw sockets." I totally disagree with that statement, as XML Web Services are decidedly NOT about that level of abstraction. If you like talking with XmlWriter and raw sockets, why not yank the <soap:envelope> and those pesky namespaces? ;) If so, there's already a spec for you.
这是不符合WS-I基本概要文件的Web服务,因为它在<soap:Body>下具有多个子节点。 Craig缪斯说: “对我来说,这看起来像是更好的XML;更像是如果我仅使用XmlWriter和原始套接字,该怎么做。” 我完全不同意该声明,因为XML Web Services绝对与该抽象级别无关。 如果您喜欢使用XmlWriter和原始套接字,为什么不使用<soap:envelope>和那些讨厌的名称空间呢? ;)如果是这样,那么已经有适合您的规范。
Additionally this places even more pressure on the HTTP SOAPAction header, which was always a bad idea. Fundamentally (at least in my World View) SOAP messages should be transport neutral and that's what wsa:Action is for.
另外,这给HTTP SOAPAction标头带来了更大的压力,这始终是一个坏主意。 从根本上(至少在我的世界视图中),SOAP消息应该是传输无关的,这就是wsa:Action的目的。
So, conclusion? Be explicit. Use Request and Response messages as ins and outs for your Web Services, call them out and use SoapParameterStyle.Bare to avoid the extra wrapping element. Tim's list of reasons why is excellent.
那么,结论呢? 要明确。 将请求消息和响应消息用作Web服务的内容,调用它们并使用SoapParameterStyle.Bare以避免多余的包装元素。 蒂姆之所以出色的原因清单。
翻译自: https://www.hanselman.com/blog/docliteralbare-in-xml-web-services-my-thoughts-on-all-this
c++中literal
这篇关于c++中literal_XML Web Services中的Doc / Literal / Bare-我对此的看法。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!