基于SOAP的RPC样式Web服务的python客户端

时间:2014-12-30 10:35:15

标签: java python web-services soap

我有一个简单的基于SOAP的RPC风格的Web服务,用java编写。它有简单的字符串方法,它取客户端的字符串值和display.Client也用java编写。但我怎么能写一个python客户端来做同样的事情?谢谢。

下面给出了使用过的代码。

服务端点

import javax.jws.WebService;

//Service Implementation
@WebService(endpointInterface = "com.test.webservice.HelloWorld")
public class HelloWorldImpl implements HelloWorld{

@Override
public String getHelloWorldAsString(String name) {
    return "Hello World JAX-WS " + name;
}

}

Java Web服务客户端

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.test.webservice.HelloWorld;

public class HelloWorldClient{

public static void main(String[] args) throws Exception {

URL url = new URL("http://localhost:9999/ws/hello?wsdl");

    //1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
    QName qname = new QName("http://webservice.test.com/", "HelloWorldImplService");

    Service service = Service.create(url, qname);

    HelloWorld hello = service.getPort(HelloWorld.class);

    System.out.println(hello.getHelloWorldAsString("name"));

}

}

}

1 个答案:

答案 0 :(得分:0)

得到答案:

import suds

class Client:
def __init__(self):
    self.client = suds.client.Client("http://localhost:9999/ws/hello?wsdl")

def getHelloWorldAsString(self):
    return self.client.service.getHelloWorldAsString("name")

if(__name__ == "__main__"):
client = Client()
result = client.getHelloWorldAsString()
print result

来源: - http://www.codeproject.com/Articles/238778/Web-Services-in-Ruby-Python-and-Java