@H_301_6@ 在前台UI确认后,终于进入到后台服务的搭建及实现中。所及而来的问题就出现了,为了提高后台程序的可用性。设计初期决定,通过搭建java WebService实现。准备工作还是比较充分的,创建WebService框架,实现接口方法。通过建立测试客户端调用java WebService方法。以上内容均已通过,就在最后通过微信小程序wx.request调用WebService接口时,问题出现了。标准的java WebService返回的为xml形式的soap描述文件,并非期待的json对象或json形式的字符串。为此寻觅很多同仁分享的解决方法,终没有解决。就在昨天与妻子闲谈生活琐事时,突然给了我一些提示。自此将该问题迎刃而解。闲话少许进入正题。
@H_301_6@准备篇
@H_301_6@1. java WebService 搭建。并实现测试接口和方法。可以通过浏览器进行验证接口提供相关方法。
public class WxSmallProjectImpl implements IWxSmallProject { /** * 模糊搜索 实现 查询结果反馈 */ @Override public String getSearchResult(String queryContent) { // TODO Auto-generated method stub Common.ObjectToJson(new Object()); String result="{\"count\":3,\"data\":[{\"text\":\"demo1\"},{\"text\":\"demo2\"},{\"text\":\"demo3\"}]}"; return result; } }@H_301_6@ @H_301_6@
<?PHP //解决OpenSSL Error问题需要加第二个array参数,具体参考 http://stackoverflow.com/questions/25142227/unable-to-connect-to-wsdl $client = new SoapClient("http://localhost:8080/CXFDemo/services/wxSmallProject?wsdl", array( "stream_context" => stream_context_create( array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, ) ) ) ) ); //print_r($client->__getFunctions()); //print_r($client->__getTypes()); //调用 微信小程序 服务 成功调用 $parm = array( 'queryContent'=>$xmlPara); $result = $client->getSearchResult($parm); echo(($result->return)); } catch (SOAPFault $e) { print $e; } //include('test.html');?>@H_301_6@ @H_301_6@