7

just deployed my WCF service on a server here at my company using IIS 7.5 and everything seems to work fine. But when i set up my client application and add a server reference to the server and then use this code .

ServerReference.ServiceClient client = new ServerReference.ServiceClient();

var s = client.GetBrand("Audi", false);

I get an exception that says "object reference not set to an instance of a object". the s object should not b null (we tried the service on localhost where the we had it all in the same project where it worked).

You looked at the stackstrace and it looks like this.

21.6.2012 16:16:29

Object reference not set to an instance of an object.

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Any suggestions ?? P.S The CPU where the WCF Service is hosted doesnt have visual studios so i cant debug through it

abatishchev
  • 98,240
  • 88
  • 296
  • 433
user1279173
  • 119
  • 1
  • 1
  • 9
  • 2
    Does [WcfTestClient](http://msdn.microsoft.com/en-us/library/bb552364.aspx) work on the hosted service? Narrow it down to see if it's your implementation, or the service failing to initialize. The contract may also have changed which (depending when you last got metadata) might cause the service to fail to instantiate. – Brad Christie Jun 21 '12 at 16:44

4 Answers4

2

As I suggested in a comment, make sure you can get the data using WcfTestClient. This both confirms the service is working, and almost unit-tests the method call ensuring it's working from a client perspective.

Second, (unless you watered it down to post on SO) use the correct WCF call method as to avoid these kinds of problems. Once you introduce a dependency it's always a good idea to anticipate for failures (albeit your service, the client's internet connection, or otherwise).

Without knowing anything else about your project it's tough to describe how to fix it. Factors like old WSDL, misconfigured *.config, unexposed endpoint on server, and other issues could be the root of the problem but given what you've shown I have no idea which it could be.

If you can provide more information I'll be glad to update my answer with any more advice I may have. For now, have a look at enabling WCF tracing on the server so you can look back through the log(s) and see if anything is afoul on the server's end (in addition to stepping through your client's call and checking).

Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • the WCF tracing is currently now working right now (dont quite understand why)... according to me research today is has something to with binding. One thing that i notice and fint interesting is that when im using a test client and call the Service which is on a localhost and i call it with a null parameter it returns the same error as the IIS hosted service does(with every parametere). Is that something to consider, p.s is there anything else u would want me to post here to understand better – user1279173 Jun 25 '12 at 14:26
1

You don't have to debug thru it. Just add WCF tracing setup in the web.config and you can get information about the originating error. See http://msdn.microsoft.com/en-us/library/ms733025.aspx

Rich
  • 2,076
  • 1
  • 15
  • 16
  • copy-id the code and puted in my webconfig , and nothing happened. No file was created or thing like that – user1279173 Jun 26 '12 at 10:14
  • Are you running the WCF service in a app pool with a different identity? If so, you need to make sure it has full control rights on the directory in question. I think with the Information level tracing, you can test just by browsing the service, you may need Verbose level. – Rich Jun 26 '12 at 13:51
0

I have the same problem in my project, in my case I found that the exception occurred in the service constructor but it's only triggered when I call any method.

kaito ked
  • 175
  • 1
  • 1
  • 15
0

Configure trace sources to emit traces and set trace levels, set activity tracing and propagation to support end-to-end trace correlation, and set trace listeners to access traces.

Windows Communication Foundation (WCF) outputs the following data for diagnostic tracing: Traces for process milestones across all components of the applications, such as operation calls, code exceptions, warnings and other significant processing events. Windows error events when the tracing feature malfunctions. See Event Logging in WCF.

Raghu Ariga
  • 1,059
  • 1
  • 19
  • 28