0
我有以下情況,我必須使用用Java編寫的使用soaplib的python編寫的Web服務。我可以導入Web服務只是在eclipse很好,但是當我嘗試調用Web服務,我得到了以下錯誤消息的方法...調用在Java中的python上運行的soaplib方法
AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: org.xml.sax.SAXParseException: Content is not allowed in prolog. faultActor: faultNode: faultDetail:
所以我試圖用建立自己的小的web服務soaplib來試試這個。以下是使用soaplib和內部http服務器運行的Web服務服務器。簡單的方法
import soaplib from soaplib.core.service import rpc, DefinitionBase from soaplib.core.model.primitive import String, Integer from soaplib.core.server import wsgi from soaplib.core.model.clazz import Array from soaplib.core.service import soap class HelloWorldService(DefinitionBase): @soap(String,_returns=String) def say_hello(self,name): results = 'Hello, %s'%name print('Hello, %s' % name) return results if __name__=='__main__': try: from wsgiref.simple_server import make_server soap_application = soaplib.core.Application([HelloWorldService], 'tns') wsgi_application = wsgi.Application(soap_application) server = make_server('pc-frank', 7789, wsgi_application) server.serve_forever() except ImportError: print "Error: example server code requires Python >= 2.5"
,這是Java類我嘗試使用
import java.rmi.RemoteException; import static java.lang.System.out; import tns.*; public class testws { public static void main(String[] args){ ApplicationProxy ws = new ApplicationProxy(); try { String test = ws.say_hello("world"); out.println(test); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
任何幫助,非常感謝!
我實際上結束了使用https://github.com/arskom/rpclib,它工作得很好,所以我建議任何人都試圖用python創建webservice。 – flazzarini 2012-03-25 21:08:08