Php 如何使用AngularJS使用SOAP Web服务?
嗯,我有一个SOAP Web服务,它通常用于PHP客户端,工作得非常好。。。通过ajax使用此php并填充我的模板 我当前的应用程序执行以下过程Php 如何使用AngularJS使用SOAP Web服务?,php,angularjs,web-services,soap,wsdl,Php,Angularjs,Web Services,Soap,Wsdl,嗯,我有一个SOAP Web服务,它通常用于PHP客户端,工作得非常好。。。通过ajax使用此php并填充我的模板 我当前的应用程序执行以下过程Angular PHP service.wsdl 我发现有可能排除这个PHP桥,直接使用SOAP Web服务,使用 但在播放示例时,我无法返回任何信息。。或错误 index.html <html ng-app="myApp"> <head> <script src="public/js/angular
Angular PHP service.wsdl
我发现有可能排除这个PHP桥,直接使用SOAP Web服务,使用
但在播放示例时,我无法返回任何信息。。或错误
index.html
<html ng-app="myApp">
<head>
<script src="public/js/angular.js"></script>
<script src="public/js/soapclient.js"></script>
<script src="public/js/angular.soap.js"></script>
<script>
angular.module('myApp', ['angularSoap'])
.factory("testService", ['$soap',function($soap){
var base_url = "http://localhost/api/1/service.wsdl";
return {
getEmpresa: function(){
var x = $soap.post(base_url,"getEmpresas");
return x;
}
}
}])
.controller('MainCtrl', function($scope, testService) {
testService.getEmpresa().then(function(response){
$scope.response = response;
});
})
</script>
</head>
<body ng-controller="MainCtrl">
{{response}}
</body>
</html>
angular.module('myApp',['angularSoap']))
.factory(“testService”,['$soap',函数($soap){
var base_url=”http://localhost/api/1/service.wsdl";
返回{
getEmpresa:函数(){
var x=$soap.post(基本url,“getEmpresas”);
返回x;
}
}
}])
.controller('MainCtrl',函数($scope,testService){
testService.getEmpresa().then(函数(响应){
$scope.response=响应;
});
})
{{response}}
服务wsdl
<!-- WSDL file generated by Zend Studio. -->
<definitions xmlns:typens="urn:Service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="Service" targetNamespace="urn:Service">
<message name="getEmpresas">
<part name="getEmpresas" type="xsd:string"/>
</message>
<message name="getEmpresasResponse">
<part name="getEmpresasReturn" type="xsd:string"/>
</message>
<portType name="HomePortType">
<operation name="getEmpresas">
<input message="typens:getEmpresas"/>
<output message="typens:getEmpresasResponse"/>
</operation>
</portType>
<binding name="HomeBinding" type="typens:HomePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getEmpresas">
<soap:operation soapAction="urn:HomeAction"/>
<input>
<soap:body namespace="urn:Service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:Service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="ServiceService">
<port name="HomePort" binding="typens:HomeBinding">
<soap:address location="http://localhost/app/homeCrtl.php"/>
</port>
</service>
</definitions>
当您发出请求时,它会通过请求负载发送一个信封
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getEmpresas xmlns="urn:Service"></getEmpresas>
</soap:Body>
</soap:Envelope>
network>Response的浏览器工具
返回上面描述的我自己的wsdl
您需要/必须更改服务器上的某些内容
谢谢从长远来看,在php和angular客户端之间使用json似乎会更干净