[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 域的更多相关文章

  1. WCF跨域解决方法及一些零碎的东西。

    之前发过一篇随笔,说的WCF配置文件配置问题.里面也配了跨域支持,但是jsoncollback只支持Get请求,Post请求是解决不了,所以这里把真正的WCF跨域问题贴出来. 话不多说,直接帖配置文件 ...

  2. WCF配置问题(配置WCF跨域)

    其它的先放一边.今天先来分享一下前段时间给公司做网站WCF服务接口的心得. 配置文件的配置问题 这里既然讨论WCF配置文件的问题,那么怎么创建的就不一一讲解了.好多博主都有提过的.所以直接分享自己开发 ...

  3. JS、JQuery和ExtJs的跨域处理

    1.什么是跨域?跨域,JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象.简单地理解就是因为JavaScript同源策略的限制,a.com 域名下的js无法操作b.com或是c.a. ...

  4. Rest webservice 和SOAP webservice

    SOAP: 简单对象访问协议(Simple Object Access Protocol,SOAP)是一种基于 XML 的协议,可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议(HTTP) ...

  5. web安全性测试用例

    建立整体的威胁模型,测试溢出漏洞.信息泄漏.错误处理.SQL 注入.身份验证和授权错误. 1.   输入验证 客户端验证 服务器端验证(禁用脚本调试,禁用Cookies) 1.输入很大的数(如4,29 ...

  6. RESTful Web Services初探

    RESTful Web Services初探 作者:杜刚 近几年,RESTful Web Services渐渐开始流行,大量用于解决异构系统间的通信问题.很多网站和应用提供的API,都是基于RESTf ...

  7. 随便聊聊 SOA & SOAP & WebService 的一些东西,以及客户端开发的代码逻辑解析

    http://blog.csdn.net/hikaliv/article/details/6459779 一天的时间调通了一个 WebService 的 Java 端的 C/S.一个 Android  ...

  8. Web 服务编程,REST 与 SOAP(转)

    原文地址:Web 服务编程,REST 与 SOAP REST 简介 在开始我们的正式讨论之前,让我们简单看一下 REST 的定义. REST(Representational State Transf ...

  9. KTHREAD 线程调度 SDT TEB SEH shellcode中DLL模块机制动态获取 《寒江独钓》内核学习笔记(5)

    目录 . 相关阅读材料 . <加密与解密3> . [经典文章翻译]A_Crash_Course_on_the_Depths_of_Win32_Structured_Exception_Ha ...

随机推荐

  1. layui日历控件设置选择日期不能超过当前日期

    layui.use('laydate', function() { var laydate = layui.laydate; laydate.render({ elem : '#begin', max ...

  2. ZingChart line 折线图表数据设置

    根据 x 坐标和 y 坐标一一对应进行设置 (x,y) { "type": "line", "series":[ {,],[,],[,],[ ...

  3. pytorch Containers的Module部分

    参考:https://pytorch.org/docs/stable/nn.html Containers Module CLASS torch.nn.Module 所有神经网络模块的基类 你定义的模 ...

  4. 003-结构型-06-组合模式(Composite)

    一.概述 将对象组合成树形结构以表示“部分一整体”的层次结构 组合模式是为了表示那些层次结构,同时部分和整体也可能是一样的结构,常见的如文件夹或者树. 通过递归手段来构造树形的对象结构,并可以通过一个 ...

  5. 查看Oracle中是否有锁表

    转: 查看Oracle中是否有锁表 2018-04-23 17:59 alapha 阅读(19450) 评论(0) 编辑 收藏 一.用dba用户登录,或者将用户赋权为DBA用户 命令: su - or ...

  6. 零基础学Python-第二章 :Python基础语法-05.基础数据类型

    打开终端,输入python3,这就进入了python的命令提示符. 输入type(8),返回的是int类型.用来type来判断当前的是什么类型. 字符串8转int类型. 数字123转字符串 布尔类型的 ...

  7. 123457123457#0#----com.MC.3or1KongLongPT867----前拼后广--3or1恐龙PtGame-mc

    com.MC.3or1KongLongPT867----前拼后广--3or1恐龙PtGame-mc

  8. 单独使用MyBatis的简单示例

    单独使用MyBatis的简单示例:mybaties-config.xml:MyBatis配置文件 <?xml version="1.0" encoding="UTF ...

  9. 【JS新手教程】JS获取当前星期几的几种方法

    该文通过获取星期几的几种方法,介绍JS里的数组,判断,和字符串截取,可以当作新手教程看,小白也看的懂.获取星期几,可通过Date()对象的getDay()获取,获取的是一个数字,对应的是0,1,2,3 ...

  10. TS - 问题解决力 - 上篇

    本文是已读书籍的内容摘要,少部分有轻微改动,但不影响原文表达. <麦肯锡工作法 - 个人竞争力提升50%的7堂课> ISBN: 9787508644691 https://book.dou ...