【问题标题】:python client for SOAP-based RPC style web service用于基于 SOAP 的 RPC 样式 Web 服务的 python 客户端
【发布时间】:2014-12-30 10:35:15
【问题描述】:

我有一个用 java 编写的简单的基于 SOAP 的 RPC 风格的 Web 服务。它有简单的字符串方法,从客户端获取字符串值并显示。客户端也是用 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"));

}

}

}

【问题讨论】:

标签: java python web-services soap


【解决方案1】:

得到答案:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 2011-01-06
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多