My WCF service has an OperationContract method (getMyObject()), which needs to use a global static variable...
Why does the WCF operation always throw an error saying the global variable is null?
- I have stepped through the WCF service host with a separate debugger, and I know the global variable is not null! - but to the client, it appears null!
The requesting client:
namespace my_Server.stuffPage {
protected void Page_Load(object sender, EventArgs e) {
ChannelFactory<IGlobal_ServiceContract> pipeFactory = new
ChannelFactory<IGlobal_ServiceContract>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://mylocalhost/myService"));
GlobalProxy = pipeFactory.CreateChannel();
ListMyObjects myObjects = GlobalProxy.getMyObjects();
}
}
The servicehost:
namespace my_WindowsService {
public class myServiceHost {
public void startWCFService() {
try {
Uri baseAddress = new Uri("net.pipe://www.myDomain.com/myService");
serviceHost = new ServiceHost(Program.g, baseAddress);
serviceHost.Open();
} catch (Exception ex) {
Debug.WriteLine(DateTime.Now + " my_WindowsService.myServiceHost .startWCFService() failed. " + ex.Message);
throw ex;
}
}
}
}
The ServiceContract interface:
[ServiceContract(Namespace = "http://mylocalhost/myService")]
public interface IGlobal_ServiceContract {
[OperationContract]
List<MyObject> getMyObject();
}
The ServiceContract object:
namespace my_WindowsService {
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[DataContract]
public class Global : IGlobal_ServiceContract {
[DataMember]
public static List<MyObject> myObject { get; set; }
public List<myObject> getMyObject() {
return Global.myObject;
}
}
}
The MyObject:
namespace my_WindowsService {
public class MyObject(){
public int x = 0;
}
}
Thanks!