服务器客户端体系结构。没有涉及IIS。这两个应用程序都是WinForm!WCF:客户端调用方法,但不返回
我做了一个共享库中的以下接口:
[ServiceContract(SessionMode=SessionMode.Required,
CallbackContract=typeof(ClientInterface))]
public interface RequestInterface
{
[OperationContract]
void Subscribe();
[OperationContract]
MyInterface GetInterface();
}
public interface MyInterface
{
[DataMember]
List<MySubInterface> SubClasses{get;}
}
public interface MySubInterface
{
[DataMember]
int Value { get; }
}
并实现了他们这样的服务器上:
public class RequestHandler : RequestInterface
{
private List<ClientInterface> iClients = new List<ClientInterface>();
public MyInterface GetInterface()
{
List<MySubInterface> tList = new List<MySubInterface>();
Form1.AddText("method invoked by:" + Thread.CurrentContext.ToString());
foreach (RealSubclass tClass in Form1.iClass.SubClasses)
{
tList.Add(new TransmissionSubclass(tClass.Value));
}
TransmissionClass tTC = new TransmissionClass(tList);
Form1.AddText("created:" + tTC);
return tTC;
}
public void Subscribe()
{
Form1.AddText("subscribing:" + OperationContext.Current.GetCallbackChannel<ClientInterface>());
iClients.Add(OperationContext.Current.GetCallbackChannel<ClientInterface>());
fireClassEvent("halloWelt");
}
}
在客户端上我做了以下的一段代码,试图调用GetInterface()方法:
ClientClass tClass = new ClientClass(this);
DuplexChannelFactory<RequestInterface> pipeFactory =
new DuplexChannelFactory<RequestInterface>(
tClass,
new NetNamedPipeBinding(),
new EndpointAddress(
"net.pipe://localhost/Request"));
RequestInterface pipeProxy = pipeFactory.CreateChannel();
//pipeProxy.Subscribe(); -- works like a charm
MyInterface tInterface = pipeProxy.GetInterface(); // doesn't work
fillListView(tInterface);
但是,当通过客户端一步一步的调试中断标记线,似乎退出此功能。
当我关闭应用程序的表单时,它只返回到'逐步'模式。
另一方面,我可以从我的服务器上的日志输出中看到,GetInterface()方法得到执行。
的TransmissionClass
和TransmissionSubclass
都在共享库,并在服务器端实现MyInterface/MySubInterface
[DataContract]
[Serializable]
public class TransmissionClass : MyInterface
{
[DataMember]
public List<MySubInterface> SubClasses{get;private set;}
public TransmissionClass(List<MySubInterface> aList)
{
SubClasses = aList;
}
public override string ToString()
{
return "TransmissionClass,Count:" + SubClasses.Count;
}
}
WCF初始化:
using (ServiceHost host = new ServiceHost(
typeof(RequestHandler),
new Uri[] { new Uri("net.pipe://localhost") }))
{
ServiceDebugBehavior tBehavior = new ServiceDebugBehavior();
if (null == tBehavior)
{
host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
}
else if (!tBehavior.IncludeExceptionDetailInFaults)
{
tBehavior.IncludeExceptionDetailInFaults = true;
}
host.AddServiceEndpoint(typeof(RequestInterface),
new NetNamedPipeBinding(), "Request");
host.Open();
Application.Run(new Form1());
host.Close();
}
非常感谢!那解决了它:-) – yas4891 2011-05-20 05:34:08
嗯。在这里有另一个问题:只要我只有几个(100)对象,它现在可以正常工作,但在增加数字(1,000,000)时会再次失败 – yas4891 2011-05-20 05:45:31
@ yas4891 - 当您有1,000,000个对象时,有什么异常? – Maxim 2011-05-20 12:56:51