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