我正在尝试在同一个WCF服务中使用SOAP和RESTful。除了一个问题之外,我已经将它除了。以下是我的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>
当我拥有所有端点时,它会出现以下错误:
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)
如果我评论json终点,事情就可以了。
你可以帮我找出原因吗?提前致谢。
答案 0 :(得分:12)
我刚刚添加了更改了json行为的绑定配置。我正在为JSON和POX使用相同的binging配置。现在我已将配置更改为:
<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>
并添加了绑定配置:
<webHttpBinding>
<binding name="WebHttp" >
<security mode="None"></security>
</binding>
<binding name="WebjsonHttp" >
<security mode="None"></security>
</binding>
</webHttpBinding>
答案 1 :(得分:2)
帮自己一个忙,并停止尝试创建一个同时执行SOAP和REST的服务。你最终会弄得一团糟。检查您的要求并选择最适合您需求的方法。