从sharepoint托管应用调用WCF服务: [英] calling a WCF service from a sharepoint hosted app :
问题描述
我正在尝试使用REST api从sharepoint托管应用程序调用WCF服务。如果我在浏览器的seprate选项卡中点击url工作正常。但是当我在sharepoint托管app中使用相同的代码时,我面临跨域问题。下面是控制台输出
i在浏览器中获取。
I am trying to call a WCF service from sharepoint hosted app using REST api. If i hit the url in a seprate tab of the browser that works fine. But when i use same code inside a sharepoint hosted app i face cross domain issue. below is the console output i gets in browser.
OPTIONS http:// depmsag-sp2013:8888 / _vti_bin / MyService / MyService.svc / CreateSalesRecord / 1/2
OPTIONS http://depmsag-sp2013:8888/_vti_bin/MyService/MyService.svc/CreateSalesRecord/1/2
jquery-1.10.2.min.js:23
XMLHttpRequest无法加载http:// depmsag- sp2013:8888 / _vti_bin /为MyService / MyService.svc / CreateSalesRecord / 1/2。请求的资源上不存在"Access-Control-Allow-Origin"标头。 Origin'http://apps-aee12a2dd34954.msagapps.nagintranet.com:8888'是
因此不允许访问。响应的HTTP状态代码为401.
jquery-1.10.2.min.js:23
XMLHttpRequest cannot load http://depmsag-sp2013:8888/_vti_bin/MyService/MyService.svc/CreateSalesRecord/1/2. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://apps-aee12a2dd34954.msagapps.nagintranet.com:8888' is
therefore not allowed access. The response had HTTP status code 401.
如果可能,请指导我一些帮助。
Please guide me with some help if possible.
相同的代码适用于可视化Web部件。
Same code works for visual web part.
问候:
Sanjay Joshi
Sanjay Joshi
推荐答案
joshi
sanjay ,如果你正在使用jQuery请求,请使用
jsonp 给您的客户请求能够到达它。
Sample :
joshi sanjay, if you are using jQuery for requests, use jsonp to your client request be able to reach it. Sample:
/* Loading JSON objects using JSONP */
(function(
){
var url ='http://www.jquery4u.com/scripts/jquery4u.settings。 json';
) { var url = 'http://www.jquery4u.com/scripts/jquery4u.settings.json';
.ajax({
type:'GET',
url:url,
async:false,
contentType: "application / json",
dataType:'jsonp'
});
})(jQuery);
.ajax({ type: 'GET', url: url, async: false, contentType: "application/json", dataType: 'jsonp' }); })(jQuery);
和你的服务器正在接收请求(WCF服务应用程序)应该也能够处理跨域请求,为此考虑在web.config上启用它。
And your server that are receiving the request (WCF Service Application) should be able to process cross domain requests too, for this considering enable it on web.config
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
这篇关于从sharepoint托管应用调用WCF服务:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!