具有多个端点的WCF单例服务?

时间:2021-01-01 16:49:33

I have a singleton wcf service (InstanceContextMode.Single) i.e MyService with multiple endpoints namely netmsmq and http. The call to netmsmq works fine but when I call it as :

我有一个单独的wcf服务(InstanceContextMode.Single),即具有多个端点的MyService,即netmsmq和http。对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:

编辑:在MyService中,MethodCall方法签名如下:

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. I am doing:

编辑2:结果是http调用试图命中netmsmq的地址。我在做:

 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. The error that I get is that :

我在web.config中使用服务激活,我在服务托管环境中设置了multipleSiteBindingsEnabled =“true”。我得到的错误是:

"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. 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.

这两种服务都托管在IIS上,并且是单个项目的一部分。我在想,也许我不能使用单一服务的多个端点。这是什么原因?我已经在它2天了,以为新鲜的眼睛可能会成功。任何帮助,将不胜感激。如果需要,我可以发布堆栈跟踪。

1 个解决方案

#1


0  

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. Like,

通过在IMyService接口中的方法声明中使用[ServiceKnownType(typeof(MyService1))]来解决该问题。喜欢,

[ServiceKnownType(typeof(MyService1))]
public void MethodCall(IMyService1 obj);

It was a serialization issue.

这是一个序列化问题。

#1


0  

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. Like,

通过在IMyService接口中的方法声明中使用[ServiceKnownType(typeof(MyService1))]来解决该问题。喜欢,

[ServiceKnownType(typeof(MyService1))]
public void MethodCall(IMyService1 obj);

It was a serialization issue.

这是一个序列化问题。