宿主主机ip为:222.31.81.214
虚拟机配置的Nat静态ip:192.168.206.10
192.168.206.10
发布webservice代码:
from soaplib.core.service import rpc, DefinitionBase
from soaplib.core.model.primitive import String,Integer,Boolean
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array
from soaplib.core.service import soap
from soaplib.core.model.clazz import ClassModel
class Rules(ClassModel):
__namespace__ = "Rules"
userId=Integer
k=Integer
class HelloWorldService(DefinitionBase):
@soap(Rules,_returns=Array(Integer))
def get_recommend(self,rules):
print rules.userId
print rules.k
cmd="spark-submit --master spark://master:7077 --driver-memory 8G --executor-memory 6G --num-executors 6 --conf spark.driver.maxResultSize=4g remmend_for_the_one.py "+str(rules.userId)+" "+str(rules.k)
print cmd
result=os.system(cmd)
print '11111'+str(result)
import remmend_for_the_one
print remmend_for_the_one.remmend
recomendList=[1,2,3]
return recomendList
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('192.168.206.10', 11111, wsgi_application)###这里必须使用ip地址,不能使用localhost,不然访问不到
server.serve_forever()
except ImportError:
print "Error: example server code requires Python >= 2.5"
问题记录:
注意ip.不然访问不到
然后
配置虚拟机
即可通过http://222.31.81.214:55555/?wsdl访问到webservice
print "Error: example server code requires Python >= 2.5"