Dart如何利用SOAP请求? [英] How does Dart leverage SOAP requests?

查看:105
本文介绍了Dart如何利用SOAP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找如何在Dart中执行SOAP请求。在查看HTTPRequest时,它实际上仅提及RESTful服务,并希望确保可以完成此操作。

I was looking up how to do SOAP requests within Dart. When looking at HTTPRequest it really only mentions RESTful services and wanted to make sure that this can be done.

现在,我有了服​​务器,用户名和密码。试图通过该服务获得成功的身份验证,这样我就可以在进行后续调用时通过auth令牌。

Right now, I have my server, username, and password. Trying to get a successful authentication via the service, so that way I have an auth token i can pass when doing subsequent calls.

在.NET中,例如执行以下操作,然后将凭据存储在服务器端会话变量中,我以此为起点在Dart中进行此操作。

It seems for example in .NET, it does the following and then stores the credential in a server side session variable which I was using as a starting point to make this in Dart.

// create web service api object
WebServiceAPI api = new WebServiceAPI();

if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["ProxyUserName"]))
{
    System.Net.NetworkCredential nc = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["ProxyUserName"], ConfigurationManager.AppSettings["ProxyPassword"], ConfigurationManager.AppSettings["ProxyDomain"]);
    System.Net.CredentialCache cc = new System.Net.CredentialCache();
    cc.Add(new Uri(api.Url), "NTLM", nc);
    api.Credentials = cc;
}

api.AuthenticateCredential("api@admin", "admin", 0, 0);
HttpContext.Current.Session["api"] = api;

编辑:我要添加一些示例数据,如果有hack,我们可以利用它来使某些东西起作用,我们也许可以抽象它并进行泛化。

I am adding some sample data such that if there is a hack we can leverage to get something working, we might be able to abstract it and genericize.

service asmx file:  
http://127.0.0.1:1337/service.asmx

Method we will be calling: (AuthenticateCredential)
http://127.0.0.1:1337/service.asmx?op=AuthenticateCredential

The sample SOAP request:
POST /service.asmx HTTP/1.1
Host: 127.0.0.1
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://foo.com/bar/320/Default/AuthenticateCredential"

<?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>
    <AuthenticateCredential xmlns="http://foo.com/barr/320/Default">
      <UserName>string</UserName>
      <Password>string</Password>
      <CurrentSystemLoginID>int</CurrentSystemLoginID>
      <CurrentCustomerID>int</CurrentCustomerID>
    </AuthenticateCredential>
  </soap:Body>
</soap:Envelope>

然后自然地,我将不得不编写并修改 string,string ,int,int

then naturally, I will have to write up and mod the string,string,int,int out of the envelope. such that the credentials are correct.

推荐答案

我已经使用Dart对Blackboard的Web服务执行了SOAP操作。为此,我必须以编程方式为每个请求构建SOAP信封。请求本身是使用http包的 post方法发送的。

I've performed SOAP actions for Blackboard's web services using Dart, so it's possible. To do so, I had to build the SOAP envelope programmatically for each request. The requests themselves were sent using the http package's 'post' method.

不能说应该如何设置请求,这取决于您的Web服务。重新尝试访问。对于HTTP标头,我发送了内容类型为 text / xml; charset = utf-8和 SOAPAction标头,用于指定SOAP方法。正文是完整的SOAP信封。

Can't say how your requests should be set up, that would depend on the web service you're attempting to access. For the HTTP headers, I sent a 'Content-Type' of 'text/xml; charset=utf-8' and a 'SOAPAction' header specifying the SOAP method. The body was the full SOAP envelope.

您可能需要花点时间才能用服务期望的正确格式/信息构建信封。我使用xml包来解析/解释响应。

You may need to play around a bit to build the envelope with the correct format/info your service expects. I used the xml package to parse/interpret the responses.

这篇关于Dart如何利用SOAP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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