2011-01-05 4 views
8

同じWCFサービスでSOAPとRESTfulを使用しようとしています。私は1つの問題から離れてそれをも痛感しました。私はすべてのエンドポイントを持っている場合SOAP、JSON、POX同じ安いwcf

<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> 

は、それが次のエラーを与える:次は私のweb.configファイルである私は、JSONのエンドポイントをコメントアウト場合

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) 

物事はうまく動作します。

あなたは私が理由を見つけるのを助けてもらえますか?

ありがとうございます。

答えて

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> 
+0

なぜ2つのエンドポイントがwsdlのバインディングを共有できないのでしょうか? – JeremyWeir

+0

@ Jayrdub別のアドレスが必要で、別のアドレスには異なるプロキシが必要だと思います。 – genericuser

+0

確かに、WebAPIのようなWCFの機能はないので、URL = "json"、address = "xml" yada yadaを取り出してURLをきれいに保つことができます。 WebApiはあなたのコンテンツタイプを調べて、あなた自身のサービスと設定のコードで素晴らしいタイムセーバーであることを示します。 – PositiveGuy

2

が自分に好意を行うと、SOAPとRESTの両方を行いつのサービスを作成しようと停止します。あなたは混乱で終わるつもりです。要件を確認し、ニーズに最も適した方法を選択します。

+1

なぜそれを言うのですか?このアプローチが適切ではないと言っているリンクがありますか、他の方法が良いですか? – genericuser

+0

@ Priya10 SOAPは、リモートオブジェクトアーキテクチャの実装をサポートするプロトコルです。 RESTはまったく異なるアーキテクチャスタイルです。正しいシナリオではどちらも有効なアプローチですが、両者は互換性がありません。 –

+2

@DarrelMiller:1人の顧客がRESTを望んでいて、もう1人がSOAPインターフェイスを本質的に同じ機能にしたい場合 – DeepSpace101

関連する問題