PDA

View Full Version : ServiceExporter proxy throws NullReferenceException in ..ctor



pootow
01-11-2010, 03:16 AM
I've just upgrade from 1.2.0 to the new 1.3.0 release.

I encountered this issue immediately.

I'm exporting a PONO as a wcf service using config:



<objects xmlns="http://www.springframework.net">
<object id="myService" type="TestingWebProject.MyService, TestingWebProject" />
<object id="MyServiceProxy" type="Spring.ServiceModel.ServiceExporter, Spring.Services">
<property name="TargetName" value="myService"/>
</object>
</objects>


and wcf config:



<services>
<service name="MyServiceProxy" behaviorConfiguration="DefaultBehavior">
<endpoint contract="TestingWebProject.IMyService"
behaviorConfiguration="REST"
binding="webHttpBinding"
/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>


I've got:


Request Error

The server encountered an error processing the request. The exception message is 'Object reference not set to an instance of an object.'. See server logs for more details. The exception stack trace is:

at MyServiceProxy..ctor()
at CreateMyServiceProxy()
at System.ServiceModel.Dispatcher.InstanceBehavior.In stanceProvider.GetInstance(InstanceContext instanceContext, Message message)
at System.ServiceModel.Dispatcher.InstanceBehavior.Ge tInstance(InstanceContext instanceContext, Message request)
at System.ServiceModel.InstanceContext.GetServiceInst ance(Message message)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process( Boolean isOperationContextSet)

Anyone who has any ideas?

pootow
01-11-2010, 05:49 AM
I found the problem was caused by not set the static __objectFactory field of the dynamic proxy.

In fact, there is a set operation exists in ServiceProxyTypeBuilder.BuildProxyType(IObjectFact ory objectFactory).


FieldInfo field = proxyType.GetField("__objectFactory", BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, objectFactory);

But this method is only called by SpringServiceHost, not ConfigurableServiceProxyTypeBuilder in ServiceExporter.

How can I fix this?
1.2.0 release does not have this problem.

and by the way, it's buggy when a service implements multi interfaces.

pootow
01-11-2010, 07:31 AM
I've create a patch for it, everything work fine:


--- C:/Users/pootow/AppData/Local/Temp/ServiceExporter.cs-rev16327.svn000.tmp.cs Mon Jan 11 16:26:43 2010
+++ C:/Users/pootow/AppData/Local/Temp/ServiceExporter.cs-rev16328.svn000.tmp.cs Mon Jan 11 16:26:43 2010
@@ -366,7 +366,7 @@
/// </summary>
protected virtual void GenerateProxy()
{
- IProxyTypeBuilder builder = new ConfigurableServiceProxyTypeBuilder(
+ ConfigurableServiceProxyTypeBuilder builder = new ConfigurableServiceProxyTypeBuilder(
TargetName, objectFactory.GetType(TargetName), this.objectName, _useServiceProxyTypeCache,
Name, Namespace, ConfigurationName, CallbackContract, ProtectionLevel, SessionMode);

@@ -384,7 +384,7 @@
builder.TargetType));
}

- proxyType = builder.BuildProxyType();
+ proxyType = builder.BuildProxyType(objectFactory);
}

#endregion

nahid
01-11-2010, 10:07 AM
Hi
please send me your client side proxy code, idon't know how to make proxy in client side, from a service that exposed by serviceexporter

pootow
01-12-2010, 01:54 AM
hi, I'm using a JSONP binding, the client code is in javascript.

I am also waiting Spring.NET team provide the client proxy for me. But I could not wait for long, I'll write a C# client support POCO interface myself, but now it is low prior, and I don't very familiar with the WCF "chanel" thing, so if I write a proxy it will be limited to a specific use.