I'm using wcf to implement a distributed application using multiple services.
One of my services must use MSMQ binding in order to receive requests asynchronously, so the requests aren't ignored when it's offline. The problem with MSMQ binding is that it is one way only and therefore I can't have methods returning within the contract. So I had to make another endpoint with a wshttpbinding.
Now I have a problem that it might even not bee related to wcf services.
The service with the msmq binding writes in a file which is read by the other servi开发者_如何转开发ce. The problem is that when the first service makes changes to the file I must restart both in order to the second one read those changes.
I'm writing the information from the file using the following:
string filename = "holder.txt";
if (!File.Exists(filename))
File.Create(filename);
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, requests_list);
stream.Close();
I close the stream so shouldn't the changes made been seen from the other service when reading it? using:
string filename = "holder.txt";
if (!File.Exists(filename))
return null;
Requests requests_list;
Stream stream = File.Open(filename, FileMode.Open);
BinaryFormatter bFormatter = new BinaryFormatter();
try
{
requests_list = (Requests)bFormatter.Deserialize(stream);
}
catch (Exception)
{
stream.Close();
return null;
}
stream.Close();
return requests_list;
Btw both methods are in a class shared by both services.
Thanks in advance
精彩评论