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中,定 ...
随机推荐
- Docs-.NET-C#-指南-语言参考-预处理器指令:#region(C# 参考)
ylbtech-Docs-.NET-C#-指南-语言参考-预处理器指令:#region(C# 参考) 1.返回顶部 1. #region(C# 参考) 2015/07/20 利用 #region,可以 ...
- ISO/IEC 9899:2011 条款6.5——表达式
6.5 表达式 1.一个表达式是操作符与操作数的一个序列,这些操作符与操作数指定了一个值的计算,或指派一个对象或一个函数,或是生成副作用,或执行上述操作的组合.对一个操作符的操作数的值计算顺序排在对该 ...
- SqStack进制计算
基于SqStack 进制计算 #include<malloc.h> #include<stdio.h> #include<stdlib.h> typedef int ...
- 【Java】Junit快速入门
Junit介绍 JUnit是一个Java语言的单元测试框架.它由Kent Beck和Erich Gamma建立,逐渐成为源于Kent Beck的sUnit的xUnit家族中最为成功的一个. JUnit ...
- Laya的调试,调试面板,断点调试
参考: 性能统计面板介绍 版本2.1.1.1 调试面板 Laya有两个调试选项,编辑模式F9. 第一个调试模式,除了调试面板,还有一个查看当前舞台对象的面板.类似白鹭的Egret Inspector. ...
- Python - Django - ORM F查询和Q查询
models.py: from django.db import models # 出版社 class Publisher(models.Model): id = models.AutoField(p ...
- systemctl service
一.systemctl常用命令 systemctl list-units ##列出当前系统服务的状态 systemctl list-unit-files ##列出服务 ...
- 【kubernetes 自带监控】 container级别cadvisor+kubelet,集群级别apiserver
apiserver https://feisky.gitbooks.io/kubernetes/components/apiserver.html kube-apiserver 支持同时提供 http ...
- 【PV和PVC】kubernetes存储 persistent volume(持久化硬盘)和 persistent volume claim(持久化硬盘请求)
报错:pod has unbound immediate PersistentVolumeClaims (repeated 11 times) pv没有满足pvc需求 https://www.cnbl ...
- 【Leetcode_easy】985. Sum of Even Numbers After Queries
problem 985. Sum of Even Numbers After Queries class Solution { public: vector<int> sumEvenAft ...