我正在尝试使用SUDS从python客户端调用webservice。当我使用复杂数据类型作为输入参数调用函数时,它没有正确传递,但是复杂的数据类型从webservice调用正确返回。
Webservice Type:
Soap Binding 1.1
Document/Literal
Webserver:
Weblogic 10.3
Python Version: 2.6.5, SUDS version: 0.3.9
这是我正在使用的代码:
Python客户端:
from suds.client import Client
url = 'http://192.168.1.3:7001/WebServiceSecurityOWSM-simple_ws-context-root/SimpleServicePort?WSDL'
client = Client(url)
print client
#simple function with no operation on input...
result = client.service.sopHello()
print result
result = client.service.add10(10)
print result
params = client.factory.create('paramBean')
print params
params.intval = 10
params.longval = 20
params.strval = 'string value'
#print "params"
print params
try:
result = client.service.printParamBean(params)
print result
except WebFault, e:
print e
try:
result = client.service.modifyParamBean(params)
print result
except WebFault, e:
print e
print params
webservice java class:
package simple_ws;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
public class SimpleService {
public SimpleService() {
}
public void sopHello(int i) {
System.out.println("sopHello: hello");
}
public int add10(int i) {
System.out.println("add10:");
return 10+i;
}
public void printParamBean(ParamBean pb) {
System.out.println(pb);
}
public ParamBean modifyParamBean(ParamBean pb) {
System.out.println(pb);
pb.setIntval(pb.getIntval()+10);
pb.setStrval(pb.getStrval()+"blah blah");
pb.setLongval(pb.getLongval()+200);
return pb;
}
}
和bean类:
package simple_ws;
public class ParamBean {
int intval;
String strval;
long longval;
public void setIntval(int intval) {
this.intval = intval;
}
public int getIntval() {
return intval;
}
public void setStrval(String strval) {
this.strval = strval;
}
public String getStrval() {
return strval;
}
public void setLongval(long longval) {
this.longval = longval;
}
public long getLongval() {
return longval;
}
public String toString() {
String stri = "\nInt val:" +intval;
String strstr = "\nstrval val:" +strval;
String strl = "\nlong val:" +longval;
return stri+strstr+strl;
}
}
所以,问题是这样的:
在python客户端中调用:client.service.printParamBean(params)
,
服务器端的输出是:
Int val:0
strval val:null
long val:0
但随叫随到:client.service.modifyParamBean(params)
客户端输出是:
(reply){
intval = 10
longval = 200
strval = "nullblah blah"
}
我在这里做错了什么?
答案 0 :(得分:0)
从外观上看,服务器端操作printParamBean
仅打印您传递的内容,但不返回任何内容。与modifyParamBean
相比,它既是印刷值又是返回值。这可能是你的问题吗?
我猜测重命名(严格来说为了清晰起见)printParamBean
到getParamBean
并让它返回你传递的内容,可能会做你期望的事。