[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. 负载均衡服务TCP端口健康检查成功,为什么在后端业务日志中出现网络连接异常信息?

    负载均衡服务TCP端口健康检查成功,为什么在后端业务日志中出现网络连接异常信息? 原文: https://help.aliyun.com/document_detail/127193.html?spm ...

  2. [原][osg][OSGEARTH]OE的关闭打开自动计算裁剪面被OE的海洋ocean影响

    在osgEarthUtil 下 Ocean.cpp 的  traverse函数中: // we don't want the ocean participating in the N/F calcul ...

  3. flutter 主页面底部导航栏实现以及主题风格设置

    import 'package:flutter/material.dart'; import 'package:flutter_app/bottom_navigation_widget.dart'; ...

  4. openresty开发系列25--openresty中使用json模块

    openresty开发系列25--openresty中使用json模块 web开发过程中,经常用的数据结构为json,openresty中封装了json模块,我们看如何使用 一)如何引入cjson模块 ...

  5. linux安装6.5.3版本elastic search

    到官网https://www.elastic.co/cn/downloads/elasticsearch下载压缩包,目前最新的版本是7.3.2,我想下6.5.3,点击下面的past release链接 ...

  6. HtmlHelper介绍

    目录 什么是HtmlHelper? 为什么要使用HtmlHelper? 清爽简单 修改路由不用改连接 很早就知道这个了,但是我一直不用.今天看了看书,准备以后都使用这个 什么是HtmlHelper? ...

  7. git切换到某个tag, 从tag切换回当前分支

    git clone 整个仓库后使用,以下命令就可以取得该 tag 对应的代码了 git checkout tag_name 但是,这时候 git 可能会提示你当前处于一个“detached HEAD& ...

  8. 利用VisualSVN修改配置库名称

    相信大家都听说过SVN的大名,至于它的用途以及如何安装不在本文范围内,这里主要讲解如何利用VisualSVN来更改配置库的名称,前提是你的SVN服务必须用VisualSVN搭建,网上几乎没有这方面的文 ...

  9. jQuery 控制網頁捲軸移動 & Ignore link '#' method jump action

    $('a.gotoheader').click(function(){ // 讓捲軸移動到 0 的位置 $(); // ignore link "#" method return ...

  10. Eureka客户端源码流程梳理

    前面梳理了Eureka服务端的流程,现在整理下客户端的流程. 1.在这个包(spring-cloud-netflix-eureka-client)里面寻找客户端启动入口相关配置,关键配置文件sprin ...