wcf可以引用COM组件,并且开启服务,让远程计算机调用吗?
我做了个例子引用了Com组件,并远程调用里面的方法.
可是程序报错.
[System.ServiceModel.CommunicationObjectFaultedException] = {"通信对象 System.ServiceModel.ServiceHost 无法用于通信,因为其处于“出错”状态。"}
这个是契约
[ServiceContract(Name = "CalculatorService", Namespace = "http://www.artech.com/")] public interface ICalculator {
#region 联机
[OperationContract] bool Connect();
#endregion
}
这个是实体方法
public class CalculatorService : ICalculator {
#region 全局变量
static CommHelper devClient; #endregion
#region 联机 public bool Connect() {
devClient = new CommHelper();
devClient.ReceiverID = @"TS0STUVWXYZ[\]";
devClient.TestingTime = 30000;
return devClient.ConnectDev("192.168.1.234", 60000, 1);
}
#endregion
}
这个控制台程序
using (ServiceHost host = new ServiceHost(typeof(CalculatorService))) { host.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "http://127.0.0.1:9999/CalculatorService"); if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null) { ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; behavior.HttpGetUrl = new Uri("http://127.0.0.1:9999/CalculatorService/metadata"); host.Description.Behaviors.Add(behavior); } host.Opened += delegate { Console.WriteLine("CalculaorService已经启动,按任意键终止服务!"); }; host.Open(); Console.Read(); }
- 3 回答
- 0 关注
- 545 浏览
添加回答
举报
0/150
提交
取消