2017-02-14 4 views
1

現在、WCFサービスを使用している古いプロジェクトが割り当てられています。MVC/WebApiとWCF認証のソリューション

重要な点は、ASP.NET MVC5とWeb APIを使用するプロジェクトを更新することです。問題は、第三者がWCFサービスを使用することであり、通信の終了を変更する意思がない可能性が高いことです。

プロジェクトの主な機能は、データを受信して​​保存し、いくつかの主題と履歴グラフの最後の状態を表示することと、データを送信すること(主題をオン/オフにする)です。

私の考えは、MVCとWeb API(データの読み込み)で構成される新しいソリューションに追加するだけで、WCFサービス(受信/送信/保存データ)をそのまま維持することでした。 可能であれば、WCFサービスでSignalRを実装することが最終目的であるため、同じプロジェクトに参加する必要があります(私は思う)。

主な問題は、MVCとWebAPIが認証の背後にとどまることですが、WCFはそれほど重要ではないということです。同じプロジェクトでWCFをテストしようとしている瞬間、「ログイン」を求めるので失敗します。

Error: Cannot obtain Metadata from http://localhost:50598/ServiceTest.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:50598/ServiceTest.svc Metadata contains a reference that cannot be resolved: ' http://localhost:50598/ServiceTest.svc '. The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '?

Log in.

Usernamehttp://localhost:50598/ServiceTest.svc The HTML document does not contain Web service discovery information.

私はウェブ上で見つけたものすべてを試しました。しかし、うまくいくものは見つかりませんでした。

私の最後は、web.configファイルをいじるに成っ:私もRouteConfig.cs

routes.IgnoreRoute("{resource}.svc/{*pathInfo}"); 
routes.IgnoreRoute("{resource}.svc"); 

にroutes.IgnoreRouteを追加し、Global.asaxの

にこれを追加しようとしました

<system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
     <binding name="UnsecuredBinding"> 
      <security mode="None"> 
      <transport clientCredentialType="None"/> 
      </security> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="serviceBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="Management.ServiceAspNetAjaxBehavior"> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="Management.ServiceTest" behaviorConfiguration="serviceBehavior"> 
     <endpoint address="" behaviorConfiguration="Management.ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="ServiceLibrary.IService" bindingConfiguration="UnsecuredBinding"/> 
     </service> 
    </services> 
    </system.serviceModel> 

protected void Application_AuthenticateRequest(object sender, EventArgs e) 
{ 
    HttpApplication context = (HttpApplication)sender; 

    if (context.Request.Url.ToString().Contains(".svc")) 
    { 
     context.Response.SuppressFormsAuthenticationRedirect = true; 
    } 
} 

私の質問:

  1. WCFメソッドをWebAPIに移行する場合、クライアント側で変更を行う必要がありますか?

  2. もしそうなら、MVC/WebAPIプロジェクトにWCFを統合するにはどうすればログイン障壁の影響を受けないのですか?

答えて

0

質問1の回答では、クライアントは変更を加える必要があります。 WCFはSOAP/XMLで、WebApiはREST/JSON(通常は初心者)です。 2については、WCFサービスが正常に機能している場合はそのままそのまま残してください。プロジェクトに直接組み込む必要はありません。Visual Studioで "サービス参照の追加"ウィザードを使用して、クライアントと対話するだけです。 これは、おそらくexperiancingのエラーは、匿名のアプリケーションと認証されたアプリケーションの同時実行をサポートしていないVisual StudioのIIS Expressインスタンスを使用しているためです.WCFサービスで認証が有効になりました。