我有3个项目。 ServHost ServManager ServClient
我的目的是使用从客户端发送数据到ServManager,让ServManager动态创建主机端点。然后,使用在ServManager中创建的ChannelFactory消耗主机端点。
ServHost.cs有以下方法:
public void createWorkerHost(Uri addr, RequiredClass workerObj)
{
ServiceHost host;
host = new ServiceHost(workerObj, addr);
host.AddServiceEndpoint(typeof(IRequiredClass), new BasicHttpBinding(), "");
var smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Open();
}
ServManager.cs有以下方法:
private void Initialize()
{
mChannelFactories = new ChannelFactory<IRequiredClass>[0];
RequiredClass rqObj = new RequiredClass(var1 obj);
var endpointAddress = CreateEndPointAddress(1);
WorkerHost.WorkerHost.createWorkerHost(new Uri(endpointAddress),rqObj);
mChannelFactories[0] = CreateChannelFactory(endpointAddress);
}
public static ChannelFactory<IRequiredClass> CreateChannelFactory(string address)
{
try
{
var binding = new BasicHttpBinding();
EndpointAddress endpointAddrress = new EndpointAddress(address);
var myChannelFactory = new ChannelFactory<IRequiredClass>(binding, endpointAddrress);
return myChannelFactory;
}
catch (Exception ex)
{
throw ex;
}
}
在这里,我可以调用ServManager并从那里获取ServClient的数据。在我调用createWorkerHost方法并创建ChannelFactory之后,当我尝试使用ChannelFactory中的通道在IRequiredClass中执行公开的方法时,我收到了TimeoutException。
因为,端点url一直在加载,直到整个项目被调试。如何在没有调试整个项目的情况下加载URL。