AngularJS - SOAP 服务与 AngularJS 模型的集成 [英] AngularJS - SOAP Service Integration With AngularJS Model

查看:25
本文介绍了AngularJS - SOAP 服务与 AngularJS 模型的集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名经验丰富的 Flex 开发人员,正在学习 AngularJS.这太混乱了!!!

I am a seasoned Flex Developer that is learning AngularJS. This is so confusing!!!

无论如何,我正在尝试通过 SOAP WSDL 请求对我的后端(在同一域中)服务器进行服务调用,并使用 AngularJS 模型对象填充数据.我正在尝试 Ajax,但在获取实际数据时遇到了一些问题.我认为我创建 SOAP 标记的方式有问题.我得到了成功的回复,但没有数据.

Anyway, I am trying to make a service call to my backend (on the same domain) server via a SOAP WSDL Request, and populate the data with an AngularJS model object. I was trying Ajax but was having some issues with getting the actual data back. I think there is something wrong with the way I created the SOAP tag. I was getting a successful response back, but no data.

在无法弄清楚Ajax方法后,我遇到了soapclient.js,发现它非常简单,代码比Ajax少.soapclient.js 为您完成大部分工作,类似于 Ajax 方法,代码量少得多.此外,使用 soapclient.js,我可以进行 SOAP 调用,还可以将数据取回 XML 格式的响应.

After not being able to figure out the Ajax method, I came across soapclient.js and found it to be extremely easy, with less code than Ajax. soapclient.js does most of the work for you, similar to the Ajax method, which makes much less code. Additionally, using soapclient.js I am able to make the SOAP call and also get data back the XML formatted response.

http://javascriptsoapclient.codeplex.com

我的问题是我正在尝试使用 AngularJS 将 XML 响应转储到 AnularJS 模型对象中.我不确定如何为我正在做的事情设置 AngularJS 项目,但我真的很想知道最好的方法,以保持我正在处理的工作分离.我一直在疯狂地搜索 Google,但大多数示例对于初学者来说似乎过于复杂.

My issue is that I am trying to use AngularJS to dump the XML response into an AnularJS model object. I am not sure how to setup the AngularJS project for what I am doing, but I would really like to know the best method in order to keep what I am working on decoupled. I have been searching Google like crazy, but most examples seem overly complicated for a beginner.

这是我所拥有的:

<html>
<head>
    <script language="JavaScript" type="text/javascript" src="jquery-1.10.1.js"></script>
    <script language="JavaScript" type="text/javascript" src="soapclient.js"></script>

    <script type="text/javascript">
        function getData() {
            var url2 = "https://myService";
            var pl = new SOAPClientParameters();

            pl.add("arg0", false);

            SOAPClient.invoke(url2, "methodToCall", pl, true, getDataCallback);
        }

        function getDataCallback(r, soapResponse) {
            alert(r.contents.payeeMailName);
        }
    </script>
</head>

<body>
<form>
    <input type="button" value="Click Here to Call Web Service" onClick="getData()" style="width: 192px">
</form>
<div id="result">Result?</div>
</body>
</html>

现在,SOAP 服务返回这样的数据:

Now, the SOAP service returns the data like this:

 <return>
    <contents>
       <eftAcctType>S</eftAcctType>
       <id>
          <djNumber>201-16-39063</djNumber>
          <djSequence>1</djSequence>
       </id>
       <payeeAddrLine1>124 Agate Drive</payeeAddrLine1>
    </contents>
    <contents>
       <eftAcctType/>
       <id>
          <djNumber>201-16-39201</djNumber>
          <djSequence>1</djSequence>
       </id>
       <payeeAddrLine1>c/o Kevin Martinez, Attorney at Law</payeeAddrLine1>
    </contents>
    <contents>
       <eftAcctType>C</eftAcctType>
       <id>
          <djNumber>201-16-38561</djNumber>
          <djSequence>1</djSequence>
       </id>
       <payeeAddrLine1>1360 South Highway 191</payeeAddrLine1>
    </contents>
    <status>0</status>
 </return>

AngularJS 中进行服务调用的正确"方式是什么,假设我这样做的方式没问题,如果没有让我知道最好的方式,然后在结果中,我如何循环遍历数据XML 响应并将其解析为 Angular 模型对象?我最终想在 DataGrid 中使用这些数据.

What is the "proper" way in AngularJS to make the service call, assuming the way I did it is ok, if not let me know the best way, and then in the result, how do I loop through the data in the XML response and parse it into an Angular model object? I eventually want to use this data in a DataGrid.

任何帮助将不胜感激.

推荐答案

晚了两年,但我已经构建了一个 Angular 模块,专门用于处理 GitHub 上的 SOAP Web 服务.

Two years late, but I have built a Angular module specifically for working with SOAP web services that is on GitHub.

https://github.com/andrewmcgivery/angular-soap

这是一篇关于如何使用它的博客文章:http://mcgivery.com/soap-web-services-angular-ionic/

Here is a blog post on how to use it: http://mcgivery.com/soap-web-services-angular-ionic/

长话短说,它允许你做这样的事情:

Long story short, it allows you to do something like this:

angular.module('myApp', ['angularSoap'])

.factory("testService", ['$soap',function($soap){
    var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx";

    return {
        HelloWorld: function(){
            return $soap.post(base_url,"HelloWorld");
        }
    }
}])

.controller('MainCtrl', function($scope, testService) {

  testService.HelloWorld().then(function(response){
    $scope.response = response;
  });

})

这篇关于AngularJS - SOAP 服务与 AngularJS 模型的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆