SOAP, JSON, and POX in the same wcf state

I am trying to use SOAP and RESTful in the same WCF service. I confirmed this, except for one problem. Below 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) 

Everything works fine if I comment on the json endpoint.

Could you help me find out why?

Thanks in advance.

+8
json soap rest wcf
source share
2 answers

I just added that I changed the binding configuration for json behavior. I used the same binging configuration for JSON and POX. Now I 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 the binding configuration is added:

  <webHttpBinding> <binding name="WebHttp" > <security mode="None"></security> </binding> <binding name="WebjsonHttp" > <security mode="None"></security> </binding> </webHttpBinding> 
+12
source share

Do yourself a favor and stop trying to create one service that performs both SOAP and REST. You will have a mess. Review your requirements and choose the approach that best suits your needs.

+2
source share

Source: https://habr.com/ru/post/650712/


All Articles