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 :
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:
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.
EDIT: MethodCall method signature is as follows in MyService:
public void MethodCall(IMyService1 obj){}
where MyService1 implements IService.
EDIT 2: Turns out that the http call is trying to hit the address of the 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:
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 :
"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."
EDIT 3: The wsdl location for http are shown as:
http://localhost/WcfService1/MyService.svc
and for msmq as:
net.msmq://localhost/private/WcfService1/MyService.svc
The contracts are all [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.
Yes, a wcf singleton service can have multiple endpoints.
The problem was solved by using
[ServiceKnownType(typeof(MyService1))]
over the method declaration in IMyService interface. Like,It was a serialization issue.