记一次 PHP调用Java Webservice

前两天,第三方合作公司给我们一个Webservice的链接,说是Java做的,里面有个sendMsg()方法,让我们在用php做的项目里推送消息给他们。我们公司是有用.net做的Webservice,而Java的Webservice没用过。

他们提供的东西:

1. Java Webservice:http://不给看IP:9080/mccweb/webservice/common/wsMessageService?wsdl

2. Java Webservice里的方法:sendMsg(string username, string title, string content, string code)

 

php调用代码:

 1 include('./NuSOAP/lib/nusoap.php');
 2 
 3 $client = new nusoap_client('http://不给看IP:9080/mccweb/webservice/common/wsMessageService?wsdl','wsdl');
 4 $err = $client->getError();
 5 if ($err) {
 6     echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
 7 }
 8 
 9 $param['username'] = 'andychen';
10 $param['title']    = 'test push';
11 $param['content']  = 'hello world!';
12 $param['code']     = '@w#wed%d#dkesq#@!!324skfjsds!';
13 
14 $result = $client->call('sendMsg', array('parameters' => $param));
15 echo $result;

 

运行结果:

我一看,尼玛“http://mccwebhost”这什么鬼?? 

浏览器打开“http://不给看IP:9080/mccweb/webservice/common/wsMessageService?wsdl”看看;

原来是这里出来的,那,这又是什么鬼??

我一想php是通过soap去调用Webservice的,且报错信息里有后面这个值,哦,了解了。“http://mccwebhost”这个是无效域名,被写死了。

沟通半天对方说改不了这是生成的,啊??生成的?鬼信。最后对方说他们用Nginx做了负载均衡,要了账号上服务器看了一下,我看到nginx.conf是这样的:

 

呵呵,好了是做了Nginx转发,做的不彻底,是这样的 Nginx转发

改成这样:

 1 upstream mccwebhost{
 2    ip_hash;  
 3    server  127.0.0.1:8082;  
 4 }
 5 
 6 location /mccweb/ {
 7     proxy_redirect    off;
 8     proxy_set_header  Host $host:9080;
 9     proxy_set_header  X-Real-IP $remote_addr;
10     proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
11     proxy_pass        http://mccwebhost;
12 }

 

重启Nginx,再次浏览器打开“http://不给看IP:9080/mccweb/webservice/common/wsMessageService?wsdl”看看;

好了,可以了。再运行php代码,返回0。对方说是参数传递不成功。为什么????经过搜索得知,要这样:

 1   include('./NuSOAP/lib/nusoap.php');
 2  
 3   $client = new nusoap_client('http://不给看IP:9080/mccweb/webservice/common/wsMessageService?wsdl','wsdl');
 4   $err = $client->getError();
 5   if ($err) {
 6       echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
 7   }
 8  
 9  $param['arg0'] = 'andychen';
10  $param['arg1'] = 'test push';
11  $param['arg2'] = 'hello world!';
12  $param['arg3'] = '@w#wed%d#dkesq#@!!324skfjsds!';
13  
14  $result = $client->call('sendMsg', array('parameters' => $param));
15  echo $result;

再次运行php代码,返回1。成功!为什么要这样传参呢,依据如图:

 

原文地址:https://www.cnblogs.com/bootoo/p/4960467.html