wcf - SOAP、JSON 和 POX 在同一个安静的 wcf 中

标签 wcf json rest soap

我试图在同一个 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 端点,一切正常。

你能帮我找出原因吗??

提前致谢。

最佳答案

好吧,我刚刚添加了更改 json 行为的绑定(bind)配置。我对 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> 

并添加了绑定(bind)配置:
 <webHttpBinding>
        <binding name="WebHttp"  >
          <security mode="None"></security>
        </binding>

        <binding name="WebjsonHttp"  >
          <security mode="None"></security>
        </binding>
      </webHttpBinding>

关于wcf - SOAP、JSON 和 POX 在同一个安静的 wcf 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4605419/

相关文章:

java - 如何让 RESTEasy 理解静态资源?

wcf - 控制使用 svcutil.exe 生成的 wcf 代理类名

wcf - 故障后在WCF中重用客户端类

wcf - WCF 服务中多种故障协定类型的优势

python - 使用 sqlalchemy 查询特定的 JSON 列(postgres)

java - 您可以在 Spring REST 中序列化对象的属性而不是整个对象吗? (对象是类的字段)

c# - WCF 服务 - 如何保护只有我的客户才能使用它?

javascript - JSON解析失败,带有base64编码图像的Javascript

asp.net-mvc - 如何从 ASP.NET MVC Web API 帖子中获取原始 JSON 字典?

java - java Restful Servlet 的版本控制