wcf Origin
WebHttpBinding bd = new WebHttpBinding(); //WebServiceHost sh = new WebServiceHost(typeof(Bl_x), new Uri("http://localhost/xxii"));
//ServiceHost sh = new ServiceHost(typeof(Bl_x), new Uri("http://localhost/xxii")); ServiceHost sh = new ServiceHost(typeof(Bl_x));
sh.AddServiceEndpoint(typeof(JK.IXX), bd, new Uri("http://localhost/xxii"));
foreach (var item in sh.Description.Endpoints)
{
WebHttpBehavior tmp = new WebHttpBehavior();
tmp.HelpEnabled = true;
WebHttpBehavior dds = item.Behaviors.Find<WebHttpBehavior>();
if (dds != null)
{
dds.HelpEnabled = true;
}
else
{
item.Behaviors.Add(tmp);
}
//item.Behaviors.Add(wb);
}
sh.Open();
button1.Text = "已启动";
button1.Enabled = false;
WebHttpBinding bd = new WebHttpBinding(); ChannelFactory<JK.IXX> dd = new ChannelFactory<JK.IXX>(bd, "http://localhost/xxii");
dd.Endpoint.Behaviors.Add(new WebHttpBehavior());
MessageBox.Show(dd.CreateChannel().getstr());
[Record]
[WebInvoke(UriTemplate = "poststr1", Method = "*", ResponseFormat = WebMessageFormat.Json)]
public string poststr1(csinfo cs)
{
var channelDispatcher = null as ChannelDispatcher;
if (channelDispatcher != null) // channelDispatcher.ErrorHandlers.Add(IErrorHandler); //if (string.Equals("json", format, StringComparison.OrdinalIgnoreCase))
//{
// if (WebOperationContext.Current != null)
// WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
//} ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
//if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
//{ // WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound();
// string ff = "";
// return null;
//}
//WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET,POST");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept"); OperationContext dd = OperationContext.Current; if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
{ // reply.Close();
// return "";
} if (cs == null)
{ return Xtools.json_TtoJson(new { x = "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff"), y = "dd" });
}
else
{
//OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("", ""));
var x = new { x = "poststr1的调用", a = "服务器时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff") + " A值:" + cs.a, b = "B值: " + cs.b, c = "C值:" + cs.c };
return Xtools.json_TtoJson(x); }
}
public class MessageInspector : IDispatchMessageInspector
{ public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
{ // return request;
} public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
new string('*',55); WebOperationContext.Current.OutgoingResponse.Headers.Clear();
WebOperationContext.Current.OutgoingResponse.Headers.Add("Server", "44441"); WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Allow-Headers", "Origin, X-Test-Header, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Headers");
//WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Allow-Methods", "GET, POST");
WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Allow-Credentials", "true");
WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Max-Age", "3600");
if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
{
//WebOperationContext.Current.OutgoingResponse.StatusCode =
wcf Origin的更多相关文章
- WCF REST开启Cors 解决 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 405.
现象: 编写了REST接口: [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(UriTemp ...
- WCF : 修复 Security settings for this service require Windows Authentication but it is not enabled for the IIS application that hosts this service 问题
摘要 : 最近遇到了一个奇怪的 WCF 安全配置问题, WCF Service 上面配置了Windows Authentication. IIS上也启用了 Windows Authentication ...
- Enabling CORS in WCF
Introduction This is an intermediate example of WCF as REST based solution and enabling CORS access, ...
- The service ‘xxx’ configured for WCF is not registered with the Autofac container
最近在使用autofac.wcf时,报如下异常: Exception Details: System.InvalidOperationException: The service 'xxx' conf ...
- WCF SOA --- AJAX 跨域请求处理 CORS for WCF
一.问题 跨域请求无法处理的问题,由于为了阻止恶意的网站通过JS脚本来窃取正常网站受保护的资源.所由所有的浏览器的默认策略是阻止XmlHttpRequest的跨域的异步请求. 但是对于一 ...
- WCF 启用multipleSiteBindingsEnabled 情况下报终结点地址错误
报错信息如下: Server Error in '/MyWcfService' Application. When 'system.serviceModel/serviceHostingEnviron ...
- wcf综合运用之:大文件异步断点续传
在WCF下作大文件的上传,首先想到使用的就是Stream,这也是微软推荐的使用方式.处理流程是:首先把文件加载到内存中,加载完毕后传递数据.这种处理方式对小文件,值得推荐,比如几K,几十k的图片文件, ...
- MSCRM 通过Ajax调用WCF服务
Call WCF Service from Dynamics CRM using AJAX A couple of days back, I had one of my ex-colleagues c ...
- Restful风格wcf调用2——增删改查
写在前面 上篇文章介绍如何将wcf项目,修改成restful风格的接口,并在上面提供了查询的功能,上篇文章中也感谢园友在评论中的提的建议,自己也思考了下,确实是那个道理.在urltemplate中,定 ...
随机推荐
- Spring Boot CLI——centos7
Spring Boot是一个命令行工具,用于使用Spring进行快速原型搭建.它允许你运行Groovy脚本,这意味着你可以使用类Java的语法,并且没有那么多的模板代码. 所有版本下载地址这里下载的版 ...
- ubuntu安装IntelliJ Idea及图标创建
一.下载并解压安装 二.创建桌面程序 1. cd /usr/local/applications/ 2. vi idea.desktop 3. 内容如下 [Desktop Entry] Name=In ...
- 获取并打印Spring容器中所有的Bean名称
思路: 1.实现Spring的ApplicationContextAware接口,重写setApplicationContext方法,将得到的ApplicationContext对象保存到一个静态变量 ...
- ifc osg施工现场模拟
基于ifc数据模型的施工现场模拟
- opencv4 mask_rcnn模型调(c++)
昨天有人问我关于调用mask_rcnn模型的问题,忽然想到最近三个月都没用opencv调用训练好的mask_rcnn模型了,今晚做个尝试,所以重新编译了 opencv4,跑个案例试试 #include ...
- 报错:flutter: Another exception was thrown: Could not find a generator for route RouteSettings
原因是一个工程中多次使用MaterialApphttps://stackoverflow.com/questions/49132299/could-not-find-a-generator-for-r ...
- 23andme的申请流程和注意事项
1. 申请时间 23andme的申请截止日期为每年的6月和12月:最近的一次截止日期是2019年6月12号: 23andme的委员会会在申请截止日期后的三个月后告知申请是否通过,即9月和次年3月就能得 ...
- LeetCode_345. Reverse Vowels of a String
345. Reverse Vowels of a String Easy Write a function that takes a string as input and reverse only ...
- LODOP计算结果值的合计
LODOP中可以通过表达式等方式,计算结果并显示在LODOP预览打印的表格里,计算的是table中本来存在的数据,可以用tindex指定合计哪一列(相关博文:)那一列的数值是table中实际存在的,如 ...
- 【编程基础】CppLint工具使用过程
前言 coding最好要形成一定的编程风格,一般常用的开源风格有google code style,可以使用cpplint工具检查是否符合该编程风格. 目录 1. linux系统使用过程: 2. wi ...