I am trying to have SOAP and RESTful in the same WCF service. I have ahieved it as well apart from one issue. Following is my web.config:
<service behaviorConfiguration="webBehaviour" name="MyServices">
<clear />
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp"
name="basicHttpBinding" contract="DJSharedServices.IMyServices" />
<endpoint address="ws" binding="wsHttpBinding" bindingConfiguration="WsHttp"
name="wsHttpBinding" contract="DJSharedServices.IMyServices" />
<endpoint address="web" binding="webHttpBinding" bindingConfiguration="WebHttp" behaviorConfiguration="webBehavior"
name="webHttpBinding" contract="DJSharedServices.IMyServices" />
<endpoint address="json" binding="webHttpBinding" bindingConfiguration="WebHttp" behaviorConfiguration="webJSONBehavior"
name="webJSONHttpBinding" contract="DJSharedServices.ISharedServices" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" name="mexBinding" />
</service>
</services>
When I have all the endpoints it gives the following error:
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.ServiceModel.Description.WsdlExporter.CreateWsdlBindingAndPort(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, Port& wsdlPort, Boolean& newBinding, Boolean& bindingNameWasUniquified)
at System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName)
at System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1 endpoints, XmlQualifiedName wsdlServiceQName)
at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)
at SyncInvokeGet(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
Things work fine if I comment out json end point.
Can you please help me finding out why??
Thanks in advance.
well I just added changed the binding configuration for json behaviour. I was using same binging configuration for JSON and POX. Now I have changed the configuration to:
<service behaviorConfiguration="WebBehaviour" name="MyServices">
<clear />
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp"
name="basicHttpBinding" contract="DJSharedServices.IMyServices" />
<endpoint address="ws" binding="wsHttpBinding" bindingConfiguration="WsHttp"
name="wsHttpBinding" contract="DJSharedServices.IMyServices" />
<endpoint address="web" binding="webHttpBinding" bindingConfiguration="WebHttp" behaviorConfiguration="webBehavior"
name="webHttpBinding" contract="DJSharedServices.IMyServices" />
<endpoint address="json" binding="webHttpBinding" bindingConfiguration="WebjsonHttp" behaviorConfiguration="webJSONBehavior"
name="webJSONHttpBinding" contract="DJSharedServices.IMyServices" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" name="mexBinding" />
</service>
and added binding configuration:
<webHttpBinding>
<binding name="WebHttp" >
<security mode="None"></security>
</binding>
<binding name="WebjsonHttp" >
<security mode="None"></security>
</binding>
</webHttpBinding>
Do yourself a favour and stop trying to create one service that does both SOAP and REST. You are going to end up with a mess. Review your requirements and pick the approach this is most suitable to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With