代码改变世界

Python使用SOAPpy调用.net写的WebService的乱码问题总结

2008-08-31 23:29  Jaypei  阅读(855)  评论(0编辑  收藏  举报
在.net中定义WebService时做以下改动
// 注释掉此句
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 加上这句
[SoapDocumentService(Use=System.Web.Services.Description.SoapBindingUse.Encoded)]


用SOAPpy.WSDL.Proxy而不是SOAPpy.SOAPProxy

调用函数时要写上参数名称,如:
<Do_Func>
     
<UserName>string</UserName>
     
<Password>string</Password>
</Do_Func>
调用的时候函数应该这么写:
srv.Do_Func(UserName=u"string", Password=u"string")



传递字符串参数的时候需要转成文件编码,返回值中如果有字符串也是unicode型的
#参数
lambda x: x.decode("cp936")
#返回值
lambda x: x.encode("cp936")