简体   繁体   English

将Complex数据类型与python SUDS客户端一起使用

[英]Using Complex datatype with python SUDS client

I am trying to call webservice from python client using SUDS. 我试图使用SUDS从python客户端调用webservice。 When I call a function with a complex data type as input parameter, it is not passed correctly, but complex data type is getting returned correctly froma webservice call. 当我调用具有复杂数据类型的函数作为输入参数时,它未正确传递,但是复杂的数据类型从webservice调用正确返回。

Webservice Type:
    Soap Binding 1.1
    Document/Literal 
Webserver: 
    Weblogic 10.3 
Python Version: 2.6.5, SUDS version: 0.3.9

here is the code I am using: 这是我正在使用的代码:

Python Client: 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: webservice 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;
    }

}

and the bean Class: 和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;
    }
}

so, as issue is like this: 所以,问题是这样的:

on call: client.service.printParamBean(params) in python client, output on server side is: 在调用:python客户端中的client.service.printParamBean(params) ,服务器端的输出是:

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

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

Client output is: 客户输出是:

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

What am i doing wrong here?? 我在这做错了什么?

From the looks of it the server-side operation printParamBean is only printing what you're passing it, but is not returning anything. 从它的外观来看,服务器端操作printParamBean只打印您传递的内容,但不返回任何内容。 Compared to modifyParamBean which is both printing and returning value. modifyParamBean相比, modifyParamBean是打印值又是返回值。 Could this be your problem? 这可能是你的问题吗?

I surmise that renaming (strictly for the sake of clarity) printParamBean to getParamBean and having it return what you passed it, might do what you're expecting. 我推测重命名(严格来说为了清晰起见) printParamBeangetParamBean并让它返回你传递的内容,可能会做你期望的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM