[英]Calling Web Service From Outlook Mail Add-In
I'm a bit stuck on this one problem I have with an Outlook Mail Add-In. 我对Outlook Mail加载项遇到的这个问题有些困惑。 I am using an Office 365 developer account, where the Mail Add-In will show (Online, in browser):
我使用的是Office 365开发人员帐户,邮件加载项将显示在其中(在线,在浏览器中):
I want to call a REST Web Service when I click the button. 单击按钮时,我想调用REST Web服务。
First, let me post my HTML: 首先,让我发布我的HTML:
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title></title>
<script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<link href="../../Content/Office.css" rel="stylesheet" type="text/css" />
<script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js" type="text/javascript"></script>
<!-- To enable offline debugging using a local reference to Office.js, use: -->
<!-- <script src="../../Scripts/Office/MicrosoftAjax.js" type="text/javascript"></script> -->
<!-- <script src="../../Scripts/Office/1.1/office.js" type="text/javascript"></script> -->
<link href="../App.css" rel="stylesheet" type="text/css" />
<script src="../App.js" type="text/javascript"></script>
<link href="Home.css" rel="stylesheet" type="text/css" />
<script src="Home.js" type="text/javascript"></script>
</head>
<body>
<!--Header and Footer tags not supported-->
<div id="content-main">
Click this button to test the create method
<br />
<label id="lblMessage">Message will appear here</label>
<button id="btnTest" type="button">Perform Test Create</button>
<!--<iframe id="my_api_iframe"></iframe>-->
</div>
</body>
</html>
This is the HTML for what we see in the first screenshot. 这是我们在第一个屏幕截图中看到的HTML。
The Office.initialize JS code, for those who want to see: Office.initialize JS代码,供那些想看的人参考:
Office.initialize = function (reason) {
//_mailbox = Office.context.mailbox;
////Request identity token from Exchange Server.
//_mailbox.getUserIdentityTokenAsync(getTokenCallback);
$(document).ready(function () {
app.initialize();
//SET Variables
loggedInUserDisplayName = Office.context.mailbox.userProfile.displayName;
loggedInUserEmailAddress = Office.context.mailbox.userProfile.emailAddress;
var conversationID = Office.context.mailbox.item.conversationId;
var internetMessageID = Office.context.mailbox.item.internetMessageId;
var itemID = Office.context.mailbox.item.itemId;
//$('#lblMessage').text("ConversationID:" + convoID + " InternetMessageID:" + intMessID + " ItemID:" + itemID);
$("#btnTest").click(function () {
GetList();
//GetList2();
});
});
};
I have tried different ways to do this. 我尝试了不同的方法来做到这一点。 When the button is clicked, it calls the specified function, here's a few ways I have tried:
单击按钮后,它将调用指定的函数,这是我尝试的几种方法:
function GetList() {
jQuery.support.cors = true;
$.ajax({
type: "GET",
url: [URL to WebMethod],
success: function (data, textStatus) {
$('#lblMessage').text("Success");
},
error: function (xhr, textStatus, errorThrown) {
$('#lblMessage').text("Error: " + errorThrown + " StatusCode: " + textStatus + " XHR: " + xhr.readyState);
}
});
}
But when the button is clicked and I call this function, this is the error I get: 但是当单击按钮并调用此函数时,这是我得到的错误:
The 2nd function I tried: 我尝试的第二个功能:
function GetList2() {
$.ajax({
type: "GET",
url: [URL to WebMethod], xhr: function () {
return new ($('#my_api_iframe')[0].contentWindow.XMLHttpRequest)();
}, success: function (html) {
// format and output result
$('#lblMessage').text(html);
}, error: function (xhr, textStatus, errorThrown) {
// format and output result
$('#lblMessage').text(errorThrown);
}
});
}
But no avail. 但无济于事。 This is the error I get:
这是我得到的错误:
Last function I tried: 我尝试的最后一个功能:
function getTokenCallback(asyncResult) {
var token = asyncResult.value;
// Create a web service call and pass the token as part of the call.
_xhr = new XMLHttpRequest();
_xhr.open("GET", [URL to WebService]);
_xhr.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
_xhr.onreadystatechange = readyStateChange;
var request = new Object();
request.token = token;
request.
request.phoneNumbers = _om.get_item().getEntities().phoneNumbers;
_xhr.send(JSON.stringify(request));
}
But I get the same "access is denied" error as before, at the point where I do the _xhr.open(). 但是在执行_xhr.open()时,出现了与以前相同的“拒绝访问”错误。
Can anyone maybe help me in the right direction to get these REST Services called? 谁能在正确的方向上帮助我,让这些REST服务得到调用? They all return data in XML Format, that's why I used ContentType of "application/xml".
它们都以XML格式返回数据,这就是为什么我使用“ application / xml”的ContentType的原因。
Any help will be greatly appreciated, even if it's a completely different way than what I'm trying to do :). 任何帮助将不胜感激,即使它与我正在尝试的方法完全不同:)。
Your iframe
HTML element is commented out. 您的
iframe
HTML元素已被注释掉。 Try to uncomment it. 尝试取消注释。 At least this is why the GetList2() fails.
至少这就是为什么GetList2()失败的原因。
So change 所以改变
<!--<iframe id="my_api_iframe"></iframe>-->
to 至
<iframe id="my_api_iframe"></iframe>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.