字符串.replace vs使用对象序列化哪个更好? [英] string .replace vs using object serialization which is better?
问题描述
我正在创建一个小肥皂消息,我可以通过http POST发送,我不确定哪个更好,更有效地用于建设我的肥皂请求之间的技术
I'm creating a small soap message that i can send via http POST and i'm not sure which is better and more efficient to use in building my soap request between these to technique
- 使用模板 文件(xml) 并将其作为资源加载然后将其用作字符串然后使用system.reflections进行循环通过请求合同中的所有属性,然后根据我的
模板中定义的特定字段名对模板进行替换
- using a template file (xml) and load it up as a resource then use it as string then use system.reflections to loop thru all the properties in a request contract then do a replace on the template based on specific fieldname defined in my template
示例是:
p属性为propertycoll
for p as property in propertycoll
template = template.replace(p.name,p.getvalue(object,nothing).tostring
template = template.replace(p.name,p.getvalue(object,nothing).tostring
next
next
VS。
- 根据实际的soap消息构建对象,并根据请求合同中的内容加载属性
- building an object based from the actual soap message and load the properties based from what's in the request contract
示例:soap。 body..fname = contract.firstname(只是使用对象执行属性填充的一个示例)
example : soap.body..fname = contract.firstname (just an example of doing property population using objects)
然后一旦整个对象成为populater,我将序列化它以获取发布的整个消息。
and then once the whole object is populater i will serialize it to get the whole message for posting.
请告知我,我只是想知道第一个选项是否更适合小信息。
Please advise for I just want to know if the first option is better for small message or not.
谢谢
-adam fs。
推荐答案
为什么不使用"添加服务引用"或"添加Web引用"并生成可以使用的代理类?为什么要使用XML?
Why not use "Add Service Reference" or "Add Web Reference" and produce a proxy class you can use? Why play with XML?
但是如果必须播放用XML,你应该使用XML API来完成它。
从不操纵XML,就像它只是一个字符串一样。它有字符串不具备的规则。 XML API知道这些规则;字符串API没有。
But if you must play with XML, you should use an XML API to do it with. Never manipulate XML like it's "just a string". It has rules that strings do not have. The XML APIs know these rules; the string APIs do not.
这篇关于字符串.replace vs使用对象序列化哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!