WCF header 域
[OperationContract]
[WebInvoke(UriTemplate = "poststr1")]
public string poststr1(csinfo cs)
{
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);
}
[OperationContract]
[WebInvoke(UriTemplate = "poststr2", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public string poststr2(string cs)
{
var x = new { x = "poststr2的调用", a = "poststr2调用 服务器时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff") + " cs值:" + cs };
return Xtools.json_TtoJson(x);
}
function dy3() { var cs = { a: "dsfdsfds", b: "ssddddd", c: "sdfsfds" }; $.ajax({ type: "POST", url: "http://10.10.12.70/xx1100/poststr1", contentType: "application/json; charset=utf-8", //(可以) // data: '{"a":"axx","b":"bxx","c:":"cxx"}', data: JSON.stringify(cs), dataType: "json", cache: false, async: false, processData: true, success: function (json) { alert(json); var t = eval('(' + json + ')'); alert(t.x); }, error: function (xhr, ajaxOptions, thrownError) { alert("调用出错" + xhr.responseText); } }); };
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS"/>
<add name="Access-Control-Allow-Credentials" value="true"/>
<add name="Access-Control-Allow-Headers" value="Origin, X-Test-Header, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Headers"/>
<add name="Access-Control-Max-Age" value="3600"/>
</customHeaders>
</httpProtocol>
</system.webServer>
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)
{ 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")
{ } //if (WebOperationContext.Current.IncomingRequest.Method == "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-Allow-Headers", "Origin, X-Test-Header, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Headers");
// WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Max-Age", "3600");
// //WebOperationContext.Current.OutgoingResponse.Headers.Set("Access-Control-Allow-Methods", "GET, POST");
// //HttpContext.Current.Response.End(); ////WebOperationContext.Current.CreateTextResponse("OK").Close();
// //WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NoContent;
//}
//HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
//HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
//HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");
//HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Test-Header, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Headers");
//HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "3600");
//if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
//{
// HttpContext.Current.Response.End();
//}
}
}
public class EbB : IEndpointBehavior
{ public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
// throw new NotImplementedException();
} public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
// throw new NotImplementedException(); } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new MessageInspector());
// throw new NotImplementedException();
} public void Validate(ServiceEndpoint endpoint)
{
// throw new NotImplementedException();
}
}
WebHttpBinding wb = new WebHttpBinding();
sh.AddServiceEndpoint(typeof(IService1), wb, "http://localhost/xx1100");
// EnableCrossOriginResourceSharingBehavior crossOriginBehavior = new EnableCrossOriginResourceSharingBehavior();
foreach (var endpont in sh.Description.Endpoints)
{
endpont.Behaviors.Add(new EbB());
// endpont.Behaviors.Add(crossOriginBehavior);
}
sh.Open();
button1.Text = "已启动";
//[OperationContract]
//[WebInvoke(UriTemplate = "poststr1",Method="POST",ResponseFormat=WebMessageFormat.Json)]
//string poststr1(csinfo cs);
[OperationContract]
[WebInvoke(UriTemplate = "poststr1",Method="*", ResponseFormat = WebMessageFormat.Json)]
string poststr1(csinfo cs); //[OperationContract]
//[WebInvoke(UriTemplate = "poststr1", Method = "OPTIONS")]
//void poststr12();
//void IService1.poststr12()
//{
// string STR = "DDD";
// // throw new NotImplementedException();
//} public string poststr1(csinfo cs)
{
//if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
//{
// WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
// WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST");
// WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");
// WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound();
// string ff = "";
// return null;
//}
//WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
{
// reply.Close();
return "";
} if (cs == null)
{
return Xtools.json_TtoJson("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff"));
}
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 string poststr2(string cs)
{
var x = new { x = "poststr2的调用", a = "poststr2调用 服务器时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff") + " cs值:" + cs };
return Xtools.json_TtoJson(x);
} }
WCF header 域的更多相关文章
- WCF跨域解决方法及一些零碎的东西。
之前发过一篇随笔,说的WCF配置文件配置问题.里面也配了跨域支持,但是jsoncollback只支持Get请求,Post请求是解决不了,所以这里把真正的WCF跨域问题贴出来. 话不多说,直接帖配置文件 ...
- WCF配置问题(配置WCF跨域)
其它的先放一边.今天先来分享一下前段时间给公司做网站WCF服务接口的心得. 配置文件的配置问题 这里既然讨论WCF配置文件的问题,那么怎么创建的就不一一讲解了.好多博主都有提过的.所以直接分享自己开发 ...
- JS、JQuery和ExtJs的跨域处理
1.什么是跨域?跨域,JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象.简单地理解就是因为JavaScript同源策略的限制,a.com 域名下的js无法操作b.com或是c.a. ...
- Rest webservice 和SOAP webservice
SOAP: 简单对象访问协议(Simple Object Access Protocol,SOAP)是一种基于 XML 的协议,可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议(HTTP) ...
- web安全性测试用例
建立整体的威胁模型,测试溢出漏洞.信息泄漏.错误处理.SQL 注入.身份验证和授权错误. 1. 输入验证 客户端验证 服务器端验证(禁用脚本调试,禁用Cookies) 1.输入很大的数(如4,29 ...
- RESTful Web Services初探
RESTful Web Services初探 作者:杜刚 近几年,RESTful Web Services渐渐开始流行,大量用于解决异构系统间的通信问题.很多网站和应用提供的API,都是基于RESTf ...
- 随便聊聊 SOA & SOAP & WebService 的一些东西,以及客户端开发的代码逻辑解析
http://blog.csdn.net/hikaliv/article/details/6459779 一天的时间调通了一个 WebService 的 Java 端的 C/S.一个 Android ...
- Web 服务编程,REST 与 SOAP(转)
原文地址:Web 服务编程,REST 与 SOAP REST 简介 在开始我们的正式讨论之前,让我们简单看一下 REST 的定义. REST(Representational State Transf ...
- KTHREAD 线程调度 SDT TEB SEH shellcode中DLL模块机制动态获取 《寒江独钓》内核学习笔记(5)
目录 . 相关阅读材料 . <加密与解密3> . [经典文章翻译]A_Crash_Course_on_the_Depths_of_Win32_Structured_Exception_Ha ...
随机推荐
- OpenCv dnn模块扩展研究(1)--style transfer
一.opencv的示例模型文件 使用Torch模型[OpenCV对各种模型兼容并包,起到胶水作用], 下载地址: fast_neural_style_eccv16_starry_night.t7 ...
- ImageSwitcher 图片切换器
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- ActionBar 自定义布局定义
ActionBar 自定义布局定义 Android系统中ActionBar默认的布局不美观且难于控制,通过为ActionBar自定义布局的方式可以灵活控制ActionBar. 效果: 工具/原料 ...
- 服务器端实时推送技术之SseEmitter的用法
这是SpringMVC提供的一种技术,可以实现服务端向客户端实时推送数据.用法非常简单,只需要在Controller提供一个接口,创建并返回SseEmitter对象,发送数据可以在另一个接口调用其se ...
- 【转载】 KL距离(相对熵)
原文地址: https://www.cnblogs.com/nlpowen/p/3620470.html ----------------------------------------------- ...
- 实战二:LoadRunner创建一个测试脚本
问题一:执行脚本浏览器不能自动启动??? 原因:loadrunner11只支持IE9以下浏览器和火狐低版本浏览器 解决办法:1.IE浏览器取消勾选[启用第三方浏览器扩展]启动IE,从[工具]进入[In ...
- oracle11g 查询临时表空间的使用率和正在使用临时表空间的用户
转: oracle11g 查询临时表空间的使用率和正在使用临时表空间的用户 原创 Oracle 作者:记录每一次错误 时间:2018-12-21 15:46:33 11179 0 今天开发反映说临时表 ...
- Qt连接数据库
Qt连接数据库,参数设置 //连接数据库 bool VCManageDatabase::connectMYSQL() { //判断testConnect连接是否存在并连接 if (QSqlDataba ...
- win8(x64)下,重新安装delphi 2007时出现“Invalid Serial Number”,如何解决?
1)在添加删除程序里卸载delphi 2007 2)删除C:\ProgramData\CodeGear 3)删除C:\Program Files (x86)CodeGear 4)删除d:\Progra ...
- Spring4.X整合redis
包和版本的依赖关系很严重 我的配置 spring-data-redis-1.6.6.RELEASE.jar spring-tx-4.2.5.RELEASE.jar redis-2.7.2.jar co ...