[英]WCF singleton service with multiple endpoints?
I have a singleton wcf service ( InstanceContextMode.Single
) ie MyService with multiple endpoints namely netmsmq and http. 我有一个单例wcf服务(
InstanceContextMode.Single
),即MyService具有多个终结点,即netmsmq和http。 The call to netmsmq works fine but when I call it as : 对netmsmq的调用工作正常,但是当我将其称为:
Binding bin = new BasicHttpBinding();
EndpointAddress end = new EndpointAddress("http://localhost/WcfService1/MyService.svc");
var obje = new ChannelFactory<IMyService>(bin, end);
obje.Open();
var factory = obje.CreateChannel();
factory.MethodCall(this) ; //this is ref of MyService1 obj
obje.Close();
in the ctor of Myservice1 I get a not Serializable exception at the line: 在Myservice1的ctor中,我在该行得到了一个不可序列化的异常:
factory.MethodCall(this);
After this I added the [Serializable]
and [KnownType(typeof(MyService1))]
attributes on MyService1 but now I get a timeout exception If I call MethodCall method. 此后,我在MyService1上添加了
[Serializable]
和[KnownType(typeof(MyService1))]
属性,但是现在我收到超时异常(如果我调用MethodCall方法)。
EDIT: MethodCall method signature is as follows in MyService: 编辑: MethodCall方法签名如下在MyService中:
public void MethodCall(IMyService1 obj){}
where MyService1 implements IService. MyService1实现IService的位置。
EDIT 2: Turns out that the http call is trying to hit the address of the netmsmq. 编辑2:原来http调用正在尝试达到netmsmq的地址。 I am doing:
我在做:
Binding binding = new BasicHttpBinding();
Uri via = new Uri("http://localhost/WcfService1/MyService.svc");
my_host.AddServiceEndpoint(type, binding, "",via);
whereas for netmsmq I am doing: 而对于netmsmq我正在做:
var contractName = serviceContract + serviceType.Name;
nbinding.CustomDeadLetterQueue = new Uri(customDlq);
my_host.AddServiceEndpoint(contractName, nbinding, "net.msmq://localhost/private/MyService.svc");
I am using service activation in web.config and I have set multipleSiteBindingsEnabled="true"
in service hosting environment. 我在web.config中使用服务激活,并且在服务托管环境中设置了
multipleSiteBindingsEnabled="true"
。 The error that I get is that : 我得到的错误是:
"The HTTP request to ' http://localhost/WcfService1/MyService.svc ' has exceeded the allotted timeout of 00:00:59.9940000. The time allotted to this operation may have been a portion of a longer timeout."
“对' http://localhost/WcfService1/MyService.svc '的HTTP请求已超过分配的超时时间00:00:59.9940000。分配给该操作的时间可能是较长超时的一部分。”
EDIT 3: The wsdl location for http are shown as: 编辑3: http的wsdl位置显示为:
http://localhost/WcfService1/MyService.svc
and for msmq as: 对于msmq为:
net.msmq://localhost/private/WcfService1/MyService.svc
The contracts are all [OperationContract (IsOneWay = true)]
这些合同都是
[OperationContract (IsOneWay = true)]
Both services are hosted on IIS and are part of a single project. 两种服务都托管在IIS上,并且属于单个项目。 I was thinking that maybe I cannot use multiple endpoints of a singleton service.
我当时在想,也许我不能使用单个服务的多个端点。 Is this the reason?
这是原因吗? I have been at it for 2 days thought fresh pair of eyes might do the trick.
我已经呆了两天,以为新鲜的眼睛也许可以解决问题。 Any help would be appreciated.
任何帮助,将不胜感激。 I can post the stack trace if required.
如果需要,我可以发布堆栈跟踪。
Yes, a wcf singleton service can have multiple endpoints. 是的,一个wcf单例服务可以具有多个端点。
The problem was solved by using [ServiceKnownType(typeof(MyService1))]
over the method declaration in IMyService interface. 通过在IMyService接口中的方法声明上使用
[ServiceKnownType(typeof(MyService1))]
解决了该问题。 Like, 喜欢,
[ServiceKnownType(typeof(MyService1))]
public void MethodCall(IMyService1 obj);
It was a serialization issue. 这是一个序列化问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.