WCF problem after two async calls at once
I am trying to connect my application to azure with wcf role. Everything works fine until i call more than one wcf method at once. I think it is because threading. Exception is:
There was no endpoint listening at http://localhost:57579/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
I was searching how to add threading to wcf service and i found this:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
or
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall]
I tried to combine this properties but it doesnt work:(
this is my simple code: Client:
public MainPage()
{
InitializeComponent();
service = new Service1Client();
service.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(getDataCompleted);
service.GetDataAsync(1);
service.GetDataAsync(2);
}
void getDataCompleted(object sender, GetDataCompletedEventArgs e)
{
if (e.Error != null)
{
}
else
{
this.textBlock1.Text = e.Result;
}
}
开发者_如何转开发
Server:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
I think the problem is that you're using the same client to do two operations at the same time. Have you tried spinning up two clients and asking each of them to perform the operation?
public MainPage()
{
InitializeComponent();
service1 = new Service1Client();
service1.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(getDataCompleted);
service1.GetDataAsync(1);
service2 = new Service1Client();
service2.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(getDataCompleted);
service2.GetDataAsync(2);
}
Note there are other ways to do the async calls that won't require as much pain with subscribing / unsubscribing the event handlers.
精彩评论