2011-12-29 14 views
3

私はWcf Serviceを使用するプロジェクトを持っています。私のweb.configファイルに結合すると、次のとおりです。WCFでnet.Pipeバインディングを使用する方法

<netNamedPipeBinding> 
    <binding name="RCISPNetNamedPipeBinding" /> 
</netNamedPipeBinding> 

<service behaviorConfiguration="Fara.WcfServiceBehaviour" name="Fara.WcfService.CommonWcfService"> 
    <endpoint address="CommonServices" binding="netNamedPipeBinding" bindingConfiguration="FaraNetNamedPipeBinding" contract="Fara.Common.ServiceContract.ICommonService" /> 
</service> 

私は例外の

public class ServiceFactory : ServiceHostFactory 
{ 
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) 
    { 
     if (!IsInitialised) InitialiseService(); 
     return base.CreateServiceHost(serviceType, baseAddresses); 
    } 

} 

メッセージがあるサービスホストを作成するとき、私はランタイムエラーを持っている:私の

Could not find a base address that matches scheme net.pipe for the endpoint with binding NetNamedPipeBinding. Registered base address schemes are [http].

プロパティプロジェクトは: enter image description here

このエラーを修正するにはどうすればよいですか?

私は、Web.configファイル更新: をしかし、私の問題は解決しません!エラーメッセージとして

enter image description here enter image description here enter image description here

+0

[スキームnet.tcpと一致するベースアドレスが見つかりませんでした](http://stackoverflow.com/questions/1793119/could-not-find-a-base-address-that-の可能性のある重複matches-scheme-net-tcp) –

答えて

3

非常に明確に述べている:あなたは、バインディングnet.pipe用に定義された任意のベースアドレスを持っていません。だから1つを定義してください!

<service name="Fara.WcfService.CommonWcfService" 
      behaviorConfiguration="Fara.WcfServiceBehaviour" > 
    <host> 
     <baseAddresses> 
      <add baseAddress="net.pipe://localhost/Services" /> 
     </baseAddresses> 
    </host> 
    <endpoint 
     address="CommonServices" 
     binding="netNamedPipeBinding" bindingConfiguration="FaraNetNamedPipeBinding" 
     contract="Fara.Common.ServiceContract.ICommonService" /> 
</service> 

その後、あなたのサービスのエンドポイントは、将来の読者のためにnet.pipe://localhost/Services/CommonServices

+0

このケースをWeb.configに追加しましたが、私の問題は解決しませんでした。私の質問が更新されます。 – Ehsan

+4

@Ehsan:Visual StudioのビルトインWebサーバーを使って 'net.pipe'バインディングを使ってWCFサービスをテストすることはできません**。 'ASP.NET開発サーバー'は 'net.pipe'をサポートしていません**。サーバー側ではセルフホスティングを使用するか、IISでサービスをホストする必要があります。 –

+0

ありがとう!もう一つの質問。 'NetTcpBinding'を使ってWCFサービスをテストできますか? – Ehsan

1

だろう。

ウェブサイトに「net.pipe」というバインディングが追加されていることを確認する必要があります。

Edit Bindings

以上、ここで詳細に見ることができます。

Binding net.pipe to Default Web Site via IIS

そしてあなたはWebアプリケーション

Enabled Protocols

のプロトコルを有効にする必要があります

プロトコルはコマンドラインからも設定できます。下の行に沿った何か。他の例を見つけてください、実際のコードではなく、これをコメントとして持っていました。しかし、それは "あなたをそこに連れて行きます"。 "、net.tcp"は必須ではありません。

appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].[path='/SunService'].enabledProtocols":"http,net.pipe,net.tcp" /commit:apphost 

まだ(コマンドラインで)最初の文字列を見つけられませんでした。もし私がそれを理解したら、ここで更新します。それは "一回" "青い月に"設定なので、私は手動でそれを何度もやる。

私はbaseAddressを設定していないことに注意してください。以下は私の仕事です。コンフィグ

<services> 

    <service name="My.Concrete.MyService" 
      behaviorConfiguration="MyBehaviorOne" 
      > 

    <host> 
     <baseAddresses> 
     </baseAddresses> 
    </host> 


    <!-- IIS Address net.pipe://localhost/MyIISApplication/MyServiceFile.svc/SomeServiceNetNamedPipeAddressAbc --> 
    <endpoint 
       address = "SomeServiceNetNamedPipeAddressAbc" 
       binding = "netNamedPipeBinding" bindingConfiguration="NamedPipeBindingName1" 
       contract = "My.Interface.IMyService" > 
    </endpoint> 


    <endpoint address="mex" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange" /> 


    </service> 


</services> 


<bindings> 

    <netNamedPipeBinding> 
    <binding name="NamedPipeBindingName1" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="9000000" 
       maxConnections="500" 
       maxReceivedMessageSize="9000000" 
       receiveTimeout="00:20:00" 
       transactionFlow="false"> 
     <security mode="Transport"> 
     </security> 
    </binding> 
    </netNamedPipeBinding> 


</bindings> 


<behaviors> 


    <behavior name="MyBehaviorOne"> 
     <!-- httpGetUrl is 'relative' in IIS --> 
     <serviceMetadata httpGetEnabled="true" httpGetUrl="Metadata" 
     httpsGetEnabled="false" /> <!-- httpGetUrl is 'relative' in IIS --> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 



</behaviors> 

APPEND:

は、「IISでWebサイトの設定サイト/site.name:"NameをAPPCMD /+bindings.[protocol='net.pipe',bindingInformation='* ']

追加-bindingコマンドラインのために正しい方向にあなたを取得する必要があります

https://www.digicert.com/ssl-support/ssl-host-headers-iis-7.htm

から。ここで

蹴りのためのいくつかのWiXのカスタムアクションコード(私はインターネット上で見つけたものを主に微調整版)

using System; 
using System.Globalization; 
using System.Linq; 
using System.Security.Principal; 

using Microsoft.Deployment.WindowsInstaller; 
using Microsoft.Web.Administration; 

namespace MyCustomActionLibrary 
{ 
    public static class CustomActions 
    { 
     /// <summary> 
     /// Updates the binding for a Site. IIS. Right click a Site. Select "Edit Bindings" to see GUI of this. 
     /// </summary> 
     /// <param name="session">The session.</param> 
     /// <returns>An ActionResult</returns> 
     [CustomAction] 
     public static ActionResult UpdateBinding(Session session) 
     { 
      session.Log("Begin UpdateBinding"); 

      string siteName = session["SITE"]; 
      if (string.IsNullOrEmpty(siteName)) 
      { 
       session.Log("Property 'SITE' missing"); 
       return ActionResult.NotExecuted; 
      } 

      string bindingInformation = session["BINDINGINFORMATION"]; 
      if (string.IsNullOrEmpty(bindingInformation)) 
      { 
       session.Log("Property 'BINDINGINFORMATION' missing"); 
       return ActionResult.NotExecuted; 
      } 

      string bindingProtocol = session["BINDINGPROTOCOL"]; 
      if (string.IsNullOrEmpty(bindingProtocol)) 
      { 
       session.Log("Property 'BINDINGPROTOCOL' missing"); 
       return ActionResult.NotExecuted; 
      } 

      ActionResult result = ActionResult.Failure; 

      if (CheckRunAsAdministrator()) 
      { 
       session.Log("Start UpsertBinding."); 
       bool outcome = UpsertBinding(session, siteName, bindingInformation, bindingProtocol); 
       if (outcome) 
       { 
        result = ActionResult.Success; 
       } 

       session.Log("End UpsertBinding."); 
       return result; 
      } 
      else 
      { 
       session.Log("Not running with elevated permissions.STOP"); 
       session.DoAction("NotElevated"); 
       return ActionResult.Failure; 
      } 
     } 

     /// <summary> 
     /// Enables the protocols. Go to IIS. Pick a Site. Right Click an Application. Select "Manage Application"/"Advanced Settings". Find "Enabled Protocols" to see the GUI of this setting. 
     /// </summary> 
     /// <param name="session">The session.</param> 
     /// <returns>An ActionResult</returns> 
     [CustomAction] 
     public static ActionResult EnableProtocols(Session session) 
     { 
      session.Log("Begin EnableProtocols"); 

      string siteName = session["SITE"]; 
      if (string.IsNullOrEmpty(siteName)) 
      { 
       session.Log("Property 'SITE' missing"); 
       return ActionResult.NotExecuted; 
      } 

      string alias = session["VIRTUALDIRECTORYALIAS"]; 
      if (string.IsNullOrEmpty(alias)) 
      { 
       session.Log("Property 'VIRTUALDIRECTORYALIAS' missing"); 
       return ActionResult.NotExecuted; 
      } 

      string protocols = session["ENABLEDPROTOCOLS"]; 
      if (string.IsNullOrEmpty(protocols)) 
      { 
       session.Log("Property 'ENABLEDPROTOCOLS' missing"); 
       return ActionResult.NotExecuted; 
      } 

      try 
      { 
       if (CheckRunAsAdministrator()) 
       { 
        ServerManager manager = new ServerManager(); 

        var site = manager.Sites.FirstOrDefault(x => x.Name.ToUpper(CultureInfo.CurrentCulture) == siteName.ToUpper(CultureInfo.CurrentCulture)); 
        if (site == null) 
        { 
         session.Log("Site with name {0} not found", siteName); 
         return ActionResult.NotExecuted; 
        } 

        var application = site.Applications.FirstOrDefault(x => x.Path.ToUpper(CultureInfo.CurrentCulture).Contains(alias.ToUpper(CultureInfo.CurrentCulture))); 
        if (application == null) 
        { 
         session.Log("Application with path containing {0} not found", alias); 
         return ActionResult.NotExecuted; 
        } 

        session.Log("About to set EnabledProtocols. SITE='{0}', VIRTUALDIRECTORYALIAS='{1}', ENABLEDPROTOCOLS='{2}'.", siteName, alias, protocols); 
        application.EnabledProtocols = protocols; 
        manager.CommitChanges(); 
        session.Log("ServerManager.CommitChanges successful for setting EnabledProtocols. SITE='{0}', VIRTUALDIRECTORYALIAS='{1}', ENABLEDPROTOCOLS='{2}'.", siteName, alias, protocols); 

        return ActionResult.Success; 
       } 
       else 
       { 
        session.Log("Not running with elevated permissions.STOP"); 
        session.DoAction("NotElevated"); 
        return ActionResult.Failure; 
       } 
      } 
      catch (Exception exception) 
      { 
       session.Log("Error setting enabled protocols: {0}", exception.ToString()); 
       return ActionResult.Failure; 
      } 
     } 

     private static bool UpsertBinding(Session session, string sitename, string bindingInformation, string bindingProtocol) 
     { 
      bool result; 

      session.Log(string.Format("(SiteName)='{0}'", sitename)); 
      session.Log(string.Format("(BindingInformation)='{0}'", bindingInformation)); 
      session.Log(string.Format("(BindingProtocol)='{0}'", bindingProtocol)); 

      using (ServerManager serverManager = new ServerManager()) 
      { 
       Site site = serverManager.Sites.FirstOrDefault(x => x.Name.Equals(sitename, StringComparison.OrdinalIgnoreCase)); 

       if (null != site) 
       { 
        Binding foundBinding = site.Bindings.FirstOrDefault(b => b.Protocol.Equals(bindingProtocol, StringComparison.OrdinalIgnoreCase) && b.BindingInformation.Equals(bindingInformation, StringComparison.OrdinalIgnoreCase)); 

        if (null == foundBinding) 
        { 
         //// add bindings 
         session.Log("About add to Site.Bindings. SITE='{0}', BINDINGINFORMATION='{1}', BINDINGPROTOCOL='{2}'.", sitename, bindingInformation, bindingProtocol); 
         site.Bindings.Add(bindingInformation, bindingProtocol); 
         serverManager.CommitChanges(); 
         session.Log("ServerManager.CommitChanges successsful for adding to Site.Bindings. SITE='{0}', BINDINGINFORMATION='{1}', BINDINGPROTOCOL='{2}'.", sitename, bindingInformation, bindingProtocol); 
         result = true; 
        } 
        else 
        { 
         session.Log(string.Format("Binding already exists. (SiteName='{0}', bindingInformation='{1}', bindingProtocol='{2}')", sitename, bindingInformation, bindingProtocol)); 
         result = true; /* do not fail if the binding already exists, the point is to have the binding */ 
        } 
       } 
       else 
       { 
        session.Log(string.Format("Site does not exist. (SiteName) {0}.", sitename)); 
        result = false; 
       } 
      } 

      return result; 
     } 

     /// <summary> 
     /// Check that process is being run as an administrator 
     /// </summary> 
     /// <returns>if the process is being run as administrator</returns> 
     private static bool CheckRunAsAdministrator() 
     { 
      var identity = WindowsIdentity.GetCurrent(); 
      var principal = new WindowsPrincipal(identity); 
      return principal.IsInRole(WindowsBuiltInRole.Administrator); 
     } 
    } 
} 

packages.config

<?xml version="1.0" encoding="utf-8"?> 
<packages> 
    <package id="Microsoft.Web.Administration" version="7.0.0.0" targetFramework="net45" /> 
</packages> 

とWiXの "プロパティ" であります。

MyProperties.wxi

<?xml version="1.0" encoding="utf-8"?> 
<Include> 
    <Property Id="SITE" Value="Default Web Site" /> 
    <Property Id="BINDINGINFORMATION" Value="*" /> 
    <Property Id="BINDINGPROTOCOL" Value="net.pipe" /> 

    <Property Id="VIRTUALDIRECTORYALIAS" Value="MyWebApplicationName" /> 
    <Property Id="ENABLEDPROTOCOLS" Value="http,net.pipe" /> 
</Include> 

それから私は、タグ内に以下のネストされました。

<?include MyProperties.wxi ?> 
関連する問題