3

我正在尝试使用 SUDS 从 python 客户端调用 webservice。当我调用具有复杂数据类型作为输入参数的函数时,它没有正确传递,但是从 web 服务调用中正确返回了复杂数据类型。

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

网络服务java类:

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;
    }

}

和豆类:

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;
    }
}

所以,问题是这样的:

on call:client.service.printParamBean(params)在 python 客户端中,服务器端的输出是:

Int val:0
strval val:null
long val:0

但随叫随到:client.service.modifyParamBean(params)

客户端输出为:

(reply){
   intval = 10
   longval = 200
   strval = "nullblah blah"
 }

我在这里做错了什么?

4

1 回答 1

0

从外观上看,服务器端操作printParamBean只是打印您传递的内容,但不返回任何内容。与之相比modifyParamBean是打印和返回值。这可能是你的问题吗?

我推测重命名(为了清楚起见)printParamBeangetParamBean让它返回你传递的内容,可能会达到你的预期。

于 2010-04-07T02:28:41.080 回答