ews soap ErrorSchemaValidation swift

ews soap ErrorSchemaValidation swift

我正在尝试使用 soap 在 ews(交换 Web 服务)上进行自动发现。我只是放了重要的功能(创建 soap 消息、设置凭证和打印消息)

func ConnectToServer()
    {

        let url = NSURL(string: "https://outlook.office365.com/ews/exchange.asmx")
        let soapMessageData = constructSOAPMessage()
        var theRequest = NSMutableURLRequest(URL: url!)
        theRequest.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
        theRequest.addValue(soapMessageData.length as String, forHTTPHeaderField: "Content-Length")
        theRequest.HTTPMethod = "POST"
        theRequest.HTTPBody = soapMessageData.data

        // Create the connection and start the asynchronous call
        var conn: NSURLConnection = NSURLConnection(request: theRequest, delegate: self, startImmediately: false)!
        conn.start()

        NSLog("Started call to web service")
    }

    func constructSOAPMessage() -> (data: NSData, length: NSString) {
        var soapMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        soapMessage = "<soap:Envelope xmlns:a=\"http://schemas.microsoft.com/exchange/2010/Autodiscover\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
        soapMessage += "<soap:Header>"
        soapMessage += "<a:RequestedServerVersion>Exchange2013</a:RequestedServerVersion>"
        soapMessage += "<wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>"
        soapMessage += "<wsa:To>https://mail.microsoft.com/autodiscover/autodiscover.svc</wsa:To>"
        soapMessage += "</soap:Header>"
        soapMessage += "<soap:Body>"
        soapMessage += "<a:GetUserSettingsRequestMessage xmlns:a=\"http://schemas.microsoft.com/exchange/2010/Autodiscover\">"
        soapMessage += "<a:Request>"
        soapMessage += "<a:Users>"
        soapMessage += "<a:User>"
         soapMessage += "<a:Mailbox>RoomMailBox@Adress.com</a:Mailbox>"
        soapMessage += "</a:User>"
        soapMessage += "</a:Users>"
        soapMessage += "<a:RequestedSettings>"
        soapMessage += "<a:Setting>InternalEwsUrl</a:Setting>"
        soapMessage += "<a:Setting>ExternalEwsUrl</a:Setting>"
        soapMessage += "</a:RequestedSettings>"
        soapMessage += "</a:Request>"
        soapMessage += "</a:GetUserSettingsRequestMessage>"
        soapMessage += "</soap:Body>"
        soapMessage += "</soap:Envelope>"
        return (soapMessage.dataUsingEncoding(NSUTF8StringEncoding)!, "\(count(soapMessage))")
    }



func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge) {
            println(challenge.protectionSpace.host)
            if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust && challenge.protectionSpace.host == "outlook.office365.com" {
                let credential = NSURLCredential(user: "serviceAccount@adresse.com", password: "LoginAccount", persistence: NSURLCredentialPersistence.None)
                challenge.sender.useCredential(credential, forAuthenticationChallenge: challenge)
            } else {
                challenge.sender.performDefaultHandlingForAuthenticationChallenge!(challenge)
            }
        }


 func connectionDidFinishLoading(connection: NSURLConnection!) {
        //Finished receiving data and convert it to a JSON object
        var err: NSError

        println(NSString(data: data, encoding:NSUTF8StringEncoding) as! String)
    }

我从服务器收到此错误:

<?xml version="1.0" encoding="utf-8"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Body>
            <s:Fault>
                <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">
                    a:ErrorSchemaValidation
                </faultcode>
                <faultstring xml:lang="en-US">
                    The request failed schema validation: Could not find schema information for the element 'http://schemas.microsoft.com/exchange/2010/Autodiscover:GetUserSettingsRequestMessage'.
                </faultstring>
                <detail>
                    <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">
                        ErrorSchemaValidation
                    </e:ResponseCode>
                    <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">
                        The request failed schema validation.
                    </e:Message>
                    <t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
                        <t:LineNumber>1
                        </t:LineNumber>
                        <t:LinePosition>290
                        </t:LinePosition>
                        <t:Violation>
                            Could not find schema information for the element 'http://schemas.microsoft.com/exchange/2010/Autodiscover:GetUserSettingsRequestMessage'.
                        </t:Violation>
                    </t:MessageXml>
                 </detail>
            </s:Fault>
        </s:Body>
    </s:Envelope>

谢谢。

验证活动目录的帐户权限。