gpt4 book ai didi

swift - ews soap ErrorSchemaValidation swift

转载 作者:可可西里 更新时间:2023-11-01 02:21:32 24 4
gpt4 key购买 nike

我正在尝试使用 soap 在 ews(exchange 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>

谢谢。

最佳答案

验证事件目录上的帐户权限。

关于swift - ews soap ErrorSchemaValidation swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30625396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com