如何使用跨域在Windows服务中创建自托管WCF服务 [英] How to create self hosting WCF service in windows service using cross domain
问题描述
我有一个Windows服务,它自己托管一个WCF服务。 Windows服务包含所有逻辑。 WCF服务调用使用ajax但浏览器发送错误,如方法不允许和无访问控制允许原因。使用这个
< pre> WebServiceHost host = new WebServiceHost(typeof(Generat),new Uri(http:// localhost:8800 / GetClient));
ServiceMetadataBehavior smb = new Ser< code>< / code> viceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
我尝试过:
自我主机wcf服务成功并且Windows服务也正常启动但是当从另一个Web应用程序调用时给出错误
并使用ajax调用
$。ajax({
url:'http:// localhost:8800 / BCon / GetClient',
类型:'GET',
contentType:'application / json; charset-uf8',
dataType:json,
})。success(function(data){
alert(data);
})。error(function(error){
alert(error);
});
.ajax({
url:'http:// localhost:8800 / BCon / GetClient',
类型:'GET',
contentType: 'application / json; charset-uf8',
dataType:json ,
})。成功(函数(数据){
alert(data);
})。错误(函数(错误){
alert(错误);
});
LMGTFY [ ^ ]
感谢我为我工作
WCF:对自托管WCF REST服务的CORS支持 - 分布式服务:来自现场的注释 [ ^ ]
I have a Windows Service which self hosts a WCF service. The Windows Service contains all of the logic. The WCF Service call using ajax but browsers sending error like Method Not allowed and No Access-Control-Allow-Origin. using this
<pre>WebServiceHost host = new WebServiceHost(typeof(Generat), new Uri("http://localhost:8800/GetClient")); ServiceMetadataBehavior smb = new Ser<code></code>viceMetadataBehavior(); smb.HttpGetEnabled = true; smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(smb); host.Open();
What I have tried:
self host wcf service successfully and windows service also start properly but when call from another web application give error
and call using ajax
$.ajax({ url: 'http://localhost:8800/BCon/GetClient', type: 'GET', contentType: 'application/json;charset-uf8', dataType: "json", }).success(function (data) { alert(data); }).error(function (error) { alert(error); });
.ajax({ url: 'http://localhost:8800/BCon/GetClient', type: 'GET', contentType: 'application/json;charset-uf8', dataType: "json", }).success(function (data) { alert(data); }).error(function (error) { alert(error); });
LMGTFY[^]
Thanks its work for me
WCF: CORS support for self-hosted WCF REST service – Distributed Services: Notes from the field[^]
这篇关于如何使用跨域在Windows服务中创建自托管WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!