AJAX访问WCF 寄宿WinForm
论坛有个代码下载但是运行不了.
网上拼凑的代码
Host = new ServiceHost(typeof(WcfService1.Service1));
//绑定
System.ServiceModel.Channels.Binding httpBinding = new BasicHttpBinding();
//终结点
Host.AddServiceEndpoint(typeof(WcfService1.Service1), httpBinding, "http://localhost:8002/");
if (Host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
{
//行为
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
//元数据地址
behavior.HttpGetUrl = new Uri("http://localhost:8002/Service1");
Host.Description.Behaviors.Add(behavior);
//启动
Host.Open();
MessageBox.Show("1");
}
只能访问http://localhost:8002/Service1 返回的是XML
但是访问 http://localhost:8002/Service1/GetFun2?UserID=as&OperaID=23 里面的方法就不行