2017-08-23 5 views
0

wcfサービスを安らかなアーキテクチャに変換しようとしています。私は、POST要求をサポートするために、認証目的のためのユーザー権限をチェックするConnectToApplicationというサービスを変換することから始めました。WCFサービスをRestful Architectureとして使用する

:エンドポイント構成のための私のメタデータは

ここ

The server encountered an error processing the request. The exception message is 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml'; 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details. The exception stack trace is:

at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) 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)

です:次のエラーで

var formData={"userName":"admin", "password":"act;[email protected]","ApplicationName":"actior"} 


     $.ajax({ 
      url : "http://localhost:10220/AdministrationService/ConnectToApplication", 
      type: "POST", 
      data: formData, 



      success: function (data) { 
      alert('success'); 
      }, 
       error: function(XMLHttpRequest, textStatus, errorThrown) { 
          alert("Status: " + textStatus); alert("Error: " + errorThrown); 
       } 

     }); 

私はHTTP 400(不正な要求)を得た:次のJavaScriptコードを使用してサービスを照会するアヤックスをしようとしているとき

[OperationContract] 
     [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "ConnectToApplication/")] 

     UserPermessionDTO ConnectToApplication(string userName, string password, string ApplicationName); 

ここでは私のWCFの設定です:

<services> 
     <service name="ActiorServeurConsoleApp.AdministrationService" behaviorConfiguration="serviceBehavior"> 
      <endpoint address="" binding="webHttpBinding" contract="ActiorServeurConsoleApp.IAdministrationService" 
         behaviorConfiguration="web"> 
       <identity> 
       <dns value="localhost" /> 
       </identity> 
      </endpoint> 

      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
      <host> 
       <baseAddresses> 
       <add baseAddress="http://localhost:10220/AdministrationService/" /> 
       </baseAddresses> 
      </host> 
      </service> 
    <services> 


    <serviceBehaviors> 
     <behavior name="serviceBehavior"> 
       <serviceMetadata httpGetEnabled="false"/> 
       <serviceDebug includeExceptionDetailInFaults="true"/> 
      </behavior> 
    </serviceBehaviors> 

    <behavior name="serviceBehavior"> 
      <serviceMetadata httpGetEnabled="false"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 

答えて

0

投稿のコンテンツタイプを

content typeとして設定することができます。 "application/json;文字セット= UTF-8" 、

また、あなたはあなたのタイプをチェックしても、あなたのサービスをテストするシオマネキ、おそらく郵便配達などのツールで見ることができます。

+0

私はこれをしようと試みた。しかし、私はHTTP 307一時的なリダイレクトのエラーを得ました。 –

+0

呼び出しがあなたのコードにヒットしたのですか、それとも失敗する前に失敗しますか? – mahlatse

+0

WCFサービスをデバッグする際に私が見つけた最良のリソースの1つがhttps://docs.microsoft.com/en-us/dotnet/framework/wcf/です。あなたがあなたのサービスに送られているものを見るためにwcfサービスに問い合わせることができるはずです。 – mahlatse

関連する問題