使用带有转义字符的XML作为参数来使用WSDL URL [英] Consume WSDL url with XML with escaped chars as argument

查看:617
本文介绍了使用带有转义字符的XML作为参数来使用WSDL URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



第一个字符串参数应该是一个XML,另外2个是用户名和密码,这是我的半工作实现。

从suds.client导入客户端
url =http ://www.jonima.com.mx:3014 / sefacturapac / TimbradoService?wsdl
client = Client(url)
client.service.timbrado(XML_AS_STRING_HERE,'PRUEBA1','12345678')

当第一个参数包含转义字符(和号,引号,撇号,小于,大于)方法不起作用,因为服务器将文本解释为未转义。如果不包含任何这些字符,那么该方法的工作效果非常好。



没有&符号的XML示例可以使用
http://dl.dropbox.com/u/1990697/no_amp.xml



具有&符号的XML示例不起作用
http://dl.dropbox .com / u / 1990697 / with_amp.xml



任何想法如何传递XML与转义的字符?



它不必依赖于suds而是依赖于python。
我正在使用python 2.6(如果需要,可以使用2.7)



我也使用Django框架,不知道是否可以有用的。






额外信息:




  • 我没有权限修改SOAP服务器

  • 客户支持告诉我我的xml是正确的,他们的工作是
    他们,所以错误是在我的实现(或/ />>

解决方案

我认为suds库是这里的罪魁祸首。当您将转义的xml作为参数发送到 client.service.timbrado 方法时,它也会转义它。但是,它看到你已经像以前一样逃避了&符号:

  ... 
descripcion =EJE& amp; MPLO
...

它不会进一步逃避它(虽然它应该)。您应该通过 xml.sax.saxutils.escape 运行转义的xml,然后将其传递给 client.service.timbrado



这应该会导致上面的xml片段如下所示:

  ... 
descripcion =EJE& amp; amp; ampamp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; MPLO b

当我使用双重转义的xml运行代码时,我收到以下结果:

 <?xml version =1.0?> 
< S:Envelope xmlns:S =http://schemas.xmlsoap.org/soap/envelope/>
< S:Body>
< ns2:timbradoResponse xmlns:ns2 =http://sefactura.com>
< return>
< status> 401 - Fecha y hora degeneraciónfuera de rango< / status>
< / return>
< / ns2:timbradoResponse>
< / S:Body>
< / S:信封>

这是一个关于您的数据的错误(生成超出范围的日期和时间),而不是关于xml的格式。


I am executing a method of a SOAP web service which receives 3 string arguments with suds library.

The first string argument should be an XML and the other 2 an username and password, this is my semi-working implementation.

from suds.client import Client
url = "http://www.jonima.com.mx:3014/sefacturapac/TimbradoService?wsdl"
client = Client(url)
client.service.timbrado(XML_AS_STRING_HERE, 'PRUEBA1', '12345678')

When the first parameter contains an escaped character (ampersand, quotes, apostrophe, less than, bigger than) method does not work because the server interprets the text as if it were unescaped. If doesn't contain any of those chars the method works great

XML example without ampersand works http://dl.dropbox.com/u/1990697/no_amp.xml

XML example with ampersand doesn't work http://dl.dropbox.com/u/1990697/with_amp.xml

Any idea how can I pass XML with escaped chars?

It doesn't have to rely on suds but in python. I am using python 2.6 (How ever it could be with 2.7 if required)

I am also using Django framework, don't know if that could be useful.


Extra Info:

  • I have no access to modify SOAP server
  • Customer support told me my xml are correct and that they work for them, so the error is in my implementation (or somewhere in suds?)

解决方案

I think the suds library is the culprit here. When you send your escaped xml into suds as a parameter to the client.service.timbrado method it also escapes it. However, it sees that you have escaped the ampersand already like this:

...
descripcion="EJE&amp;MPLO"
...

And it does not escape it further (although it should). You should run your escaped xml through xml.sax.saxutils.escape before passing it to client.service.timbrado.

This should result in xml snippet above looking like this:

...
descripcion="EJE&amp;amp;MPLO"
...

When I run your code with the doubly-escaped xml, I receive the following result:

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:timbradoResponse xmlns:ns2="http://sefactura.com">
            <return>
                <status>401 - Fecha y hora de generación fuera de rango</status>
            </return>
        </ns2:timbradoResponse>
    </S:Body>
</S:Envelope>

It is an error regarding your data (date and time of generation out of range), not about the format of the xml.

这篇关于使用带有转义字符的XML作为参数来使用WSDL URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆