简体   繁体   English

iOS SOAP对Mindbody API的请求

[英]iOS SOAP request for Mindbody API

I have been trying to make SOAP requests with swift for the past few days unsuccessfully and wondering if anybody can direct me to getting a successful response. 在过去的几天中,我一直试图迅速提出SOAP请求,并想知道是否有人可以指导我获得成功的响应。 I understand that NSURLConnection is deprecated but I wanted to test to see if I can even make a successful request since all examples that I can find online used it. 我知道不赞成使用NSURLConnection,但是我想测试一下是否可以成功发出请求,因为我在网上可以找到的所有示例都使用了它。

The soap request is directly off of their API website at https://developers.mindbodyonline.com/ , which free to signup. soap请求直接从其API网站https://developers.mindbodyonline.com/上关闭,可以免费注册。

let requestURL = NSURL(string: "https://api.mindbodyonline.com/0_5/SiteService.asmx")
let myRequest = NSMutableURLRequest(URL: requestURL!)

let soapMessage =
        "<soapenv:envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://clients.mindbodyonline.com/api/0_5\">" +
        "<soapenv:header />" +
        "<soapenv:body>" +
        "<GetLocations xmlns=\"http://clients.mindbodyonline.com/api/0_5\">" +
        "<request>" +
            "<sourcecredentials>" +
            "<sourcename>Siteowner</sourcename>" +
            "<password>apitest1234</password>" +
            "<siteids> <int>-99</int> </siteids>" +
            "</sourcecredentials>" +
            "<XMLDetail>Bare</XMLDetail>" +
             "<PageSize>10</PageSize>" +
             "<CurrentPageIndex>0</CurrentPageIndex>" +
             "<Fields>" +
                "<string>Locations.Name</string>" +
                "<string>Locations.City</string>" +
             "</Fields>" +
        "</request>" +
        "</GetLocations>" +
        "</soapenv:Body> </soapenv:envelope>"


let sMessageLength = NSString(format: "%d", soapMessage.characters.count)
myRequest.addValue("text/xml; charset=UTF-8", forHTTPHeaderField: "Content-Type")
myRequest.addValue(sMessageLength as String, forHTTPHeaderField: "Content-Length")
myRequest.HTTPMethod = "POST"
myRequest.addValue("http://clients.mindbodyonline.com/api/0_5/GetLocations", forHTTPHeaderField: "SOAPAction")
myRequest.HTTPBody = soapMessage.dataUsingEncoding(NSUTF8StringEncoding)

 sConnection = NSURLConnection(request: myRequest, delegate: self)

I've tried many things but most of the time I get the following error response. 我已经尝试了很多事情,但是大多数时候我都会收到以下错误响应。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
    <faultcode>soap:Client</faultcode>
    <faultstring>Server was unable to read request. ---&gt; Request format is invalid: Missing required soap:Envelope element.
    </faultstring><detail />
</soap:Fault></soap:Body></soap:Envelope>

I cannot figure out what I am doing wrong since this code is directly off their website example. 我无法弄清楚我在做什么错,因为此代码直接来自他们的网站示例。 Thank you for your help. 谢谢您的帮助。

Going off of the XML, it looks like you're passing through the UserCredentials used to log in to the API Sandbox as your SourceCredentials. 从XML开始,好像您正在通过UserCredentials来作为SourceCredentials登录到API沙箱。

Try passing through your API Credentials listed on their developer portal and let us know if you still get this error. 尝试传递其开发者门户上列出的API凭据,并让我们知道您是否仍然遇到此错误。

Try changing the tags that you have for the SourceCredentials to use CamelCase: 尝试更改为使SourceCredentials使用CamelCase而具有的标签:

"<SourceCredentials>" +
"<SourceName>Siteowner</SourceName>" +
"<Password>apitest1234</Password>" +
"<SiteIDs> <int>-99</int> </SiteIDs>" +
"</SourceCredentials>" +

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM