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 =

  

最新文章

  1. 集群: 如何在spring 任务中 获得集群中的一个web 容器的端口号?
  2. windows内核结构
  3. 推荐:一个个人开发者搞app赚钱之后的总结!有图有真相。
  4. Spring配置多个数据源
  5. zoj 3471 Most Powerful(状态压缩dp)
  6. 简单JSONP跨域请求
  7. [Android学习笔记]RelativeLayout的使用
  8. 队列Queue FIFO先进先出 栈Stack FILO先进后出
  9. ural 1261. Tips(进制运算)
  10. 【servlet】 第一个servlet
  11. Java与算法之(6) - 八皇后问题
  12. 01 Android修改新建虚拟机存放的位置
  13. jenkins构建基于gradle的springboot项目CI采坑(采用jar方式部署)
  14. 解决:AttributeError: module &#39;requests&#39; has no attribute &#39;post&#39;”
  15. 由浅入深:CNN中卷积层与转置卷积层的关系
  16. Oracle drop table 和 truncate table对grant授权的影响
  17. JavaSE学习总结(十六)—— 泛型与泛型应用
  18. iOS NSNotificationCenter 最基本使用
  19. MySQL Crash Course #02# Chapter 3. 4 通配符. 分页
  20. Nginx反向代理websocket配置实例

热门文章

  1. ntpd服务
  2. java的List中使用filter过滤出符合特定条件的元素List
  3. eclipse连接夜神模拟器方法
  4. android -------- GifView 显示gif图片
  5. Django Timezone 处理
  6. Python - Django - 装饰器版的登陆校验
  7. Sublime Text 3能用支持的插件推荐
  8. 汉字转拼音插件:LM-PinYin.js
  9. IE6/IE7/IE8 JQuery下resize事件执行多次的解决方法
  10. [Google] 9717 取数对弈