I created my first Silverlight project in VS 2008 Express, and am trying to call a WCF webservice with it. The web service is very simple - I basically just took the default code created when using the WCF Service template from VisualStudio, renamed everything so it wasn't the default "Service1" name, and even removed the complex return type so that the only method on the contract is a method that returns a string.
On the Silverlight side, I created a new project from the Silverlight template, selecting the option to also create the containing ASP.NET web project. I've left the web project untouched, and the silverlight app is basically just a button and a text box right now.
I kicked off my WCF project in the debugger, and can load up the .svc URL in my browser, and also navigate to the WSDL.
Using svcutil.exe, I generated a c# proxy class based on this WSDL. I did not use the /async option, so my proxy class really only has 1 remote method call, the single method GetData(int value) that returns a string.
In my Silverlight page code behind, I create a new instance of my service, and then try and call GetData().
SliverServiceClient client = new SliverServiceClient ();
client.GetData(1234);
In my silverlight project, I added the following endpoint/contract configuration to ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding
name="basicHttpBinding_ISliverService"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:15:00"
sendTimeout="00:01:00"
maxBufferSize="65530"
maxReceivedMessageSize="65530"
textEncoding="utf-8">
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint
address="http://localhost:8181/SliverService.svc"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_ISliverService"
contract="ISliverService"
name="basicHttpBinding_ISliverService" />
</client>
</system.serviceModel>
</configuration>
Note that I'm using basicHttpBinding, since, as I understand it, that's the only WCF binding Silverlight supports.
My problem is that during runtime, the call client.GetData(1234) gives me a NullReferenceException. I've confirmed in the debugger that client is not null. If I inspect "client" from the debugger, I can see that the following are not null: ChannelFactory, Endpoint, State. The properties Channel and InnerChannel give an error "could not be evaluated" in the debugger.
I notice in the proxy class that GetData(int value) is simply
base.Channel.GetData(value);
The debugger wont let me step into the proxy class to see if Channel is null - but it seems like that is the only thing that can be, unless it's something from the ServiceModel library.
There is no inner exception, and the stack trace is as follows:
at System.ServiceModel.Channels.Remoting.RealProxy.Invoke(Object[] args)
at proxy_2.GetData(Int32 )
at SliverServiceClient.GetData(Int32 accountID)
at Sliver.Page.MakeSliverCall(Object state)
at Sliver.Page..ctor()
at Sliver.App.Application_Startup(Object sender, StartupEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
I do not have the endpoint configuration in the ASP.NET web project web.config (though I did try it with, and got the same error).
What on earth am I doing wrong here? It seems like it should be pretty straight forward.