WCFルーティングサービスエラー-PointDispatcherでのContractFilterの不一致

StackOverflow https://stackoverflow.com/questions/6831111

  •  27-10-2019
  •  | 
  •  

質問

状況は次のとおりです。いくつかのWCFサービスを実行している内部サーバーがあり、インターネット全体からアクセスできるようにしたいと考えています。この目的のために、私は私たちの一般のWebサーバーで実行されているルーティングサービスを書きました。

このルーティングサービスは機能しているように見えますが、メソッドを呼び出そうとすると、常に次のエラーが発生します。

アクション「http://tempuri.org/iprocessmanagementservice/listprocess」は、endpointDispatcherでの契約上の誤った誤解のため、レシーバーで処理できません。これは、契約の不一致(送信者とレシーバー間の不一致のアクション)または送信者と受信機の間の拘束力/セキュリティの不一致のいずれかが原因である可能性があります。送信者とレシーバーが同じ契約と同じ拘束力のある拘束力を持っていることを確認します(セキュリティ要件、メッセージ、トランスポート、なし)。

私はサービスからすべてのセキュリティ要件を削除しようとし、WSHTTPとBasichTTPの両方のエンドポイントを使用しました。トリックをすることは何もないようです。ただし、ルーティングサービスはMEXサービスを適切に渡しているため、SVCutilはクライアントクラスを構築できます。

コードでルーターを構成しています。ルーティングサービスには、ルーティングを提供するサービス名とルーターとサーバーのアドレスが与えられます。

ルーティングサービスの構成は次のとおりです。

<MES.RoutingService.Properties.Settings>
   <setting name="RouterAddress" serializeAs="String">
    <value>http://localhost:8781/</value>
   </setting>
   <setting name="ServerAddress" serializeAs="String">
    <value>http://10.4.1.117:8781/</value>
   </setting>
   <setting name="Services" serializeAs="Xml">
    <value>
     <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <string>ProcessManagementService</string>
      <string>TestProcessService</string>
      <string>ProcessDataEntryService</string>
      <string>ProcessReportingService</string>
     </ArrayOfString>
    </value>
   </setting>
  </MES.RoutingService.Properties.Settings>

構成ファイルからルーターアドレス、サーバーアドレス、およびサービス名を提供して、次のコードを使用して関数を呼び出します。

var routers = new List<ServiceHost>();
        foreach (var service in _services)
        {
            var routerType = typeof(IRequestReplyRouter);
            var routerContract = ContractDescription.GetContract(routerType);
            var serviceHost = new ServiceHost(typeof (System.ServiceModel.Routing.RoutingService));             
            var serverEndpoints = new List<ServiceEndpoint>();              

            //Configure Mex endpoints
            serviceHost.AddServiceEndpoint(routerType, MetadataExchangeBindings.CreateMexHttpBinding(), _routerAddress + service + "/mex");
            serverEndpoints.Add(new ServiceEndpoint(routerContract, MetadataExchangeBindings.CreateMexHttpBinding(), new EndpointAddress(_serverAddress + service + "/mex")));

            //RAR SECURITY SMASH.
            var binding = new WSHttpBinding(SecurityMode.None);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.Security.Message.EstablishSecurityContext = false;
            binding.Security.Message.NegotiateServiceCredential = false;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.None;

            //Configure WsHttp endpoints
            serviceHost.AddServiceEndpoint(routerType, binding, _routerAddress + service);              
            serverEndpoints.Add(new ServiceEndpoint(routerContract, binding, new EndpointAddress(_serverAddress + service)));

            var basicBinding = new BasicHttpBinding();
            serviceHost.AddServiceEndpoint(routerType, basicBinding, _routerAddress + service + "/basic");
            serverEndpoints.Add(new ServiceEndpoint(routerContract, basicBinding, new EndpointAddress(_serverAddress + service + "/basic")));

            //Set Routing Tables
            var configuration = new RoutingConfiguration();
            configuration.FilterTable.Add(new MatchAllMessageFilter(), serverEndpoints);
            serviceHost.Description.Behaviors.Add(new RoutingBehavior(configuration));

            routers.Add(serviceHost);
        }
        return routers;

このサービスは、STARTでこの関数を呼び出してから、ルーターリストに戻された各サービスホストを開きます。

サーバー自体は、次のapp.configで構成されています

<system.serviceModel>
  <bindings>
   <wsHttpBinding>
    <binding name="noSecurityBinding">
     <security mode="None">
      <transport clientCredentialType="None" />
      <message establishSecurityContext="false" />
     </security>
    </binding>
   </wsHttpBinding>   
  </bindings>
  <services>
   <service name="MES.ProcessManagerServiceLibrary.ProcessManagementService">
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
     contract="MES.ProcessManagerServiceLibrary.IProcessManagementService" />
    <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
     contract="MES.ProcessManagerServiceLibrary.IProcessManagementService" />
    <host>
     <baseAddresses>
      <add baseAddress="http://localhost:8781/ProcessManagementService/" />
     </baseAddresses>
    </host>
   </service>
   <service name="MES.ProcessManagerServiceLibrary.TestProcessService">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
     contract="MES.ProcessManagerServiceLibrary.ITestProcessService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
     contract="MES.ProcessManagerServiceLibrary.ITestProcessService" />    
    <host>
     <baseAddresses>
      <add baseAddress="http://localhost:8781/TestProcessService/" />
     </baseAddresses>
    </host>
   </service>
   <service name="MES.ProcessManagerServiceLibrary.ProcessDataEntryService">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
     contract="MES.ProcessManagerServiceLibrary.IProcessDataEntryService" />
    <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
    contract="MES.ProcessManagerServiceLibrary.IProcessDataEntryService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
     <baseAddresses>
      <add baseAddress="http://localhost:8781/ProcessDataEntryService/" />
     </baseAddresses>
    </host>
   </service>
   <service name="MES.ProcessManagerServiceLibrary.ProcessReportingService">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
     contract="MES.ProcessManagerServiceLibrary.IProcessReportingService" />
    <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
    contract="MES.ProcessManagerServiceLibrary.IProcessReportingService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
     <baseAddresses>
      <add baseAddress="http://localhost:8781/ProcessReportingService/" />
     </baseAddresses>
    </host>
   </service>
  </services>
  <behaviors>
   <serviceBehaviors>
    <behavior>
     <!-- To avoid disclosing metadata information, 
     set the value below to false and remove the metadata endpoint above before deployment -->
     <serviceMetadata httpGetEnabled="True"/>
     <!-- To receive exception details in faults for debugging purposes, 
     set the value below to true. Set to false before deployment 
     to avoid disclosing exception information -->
     <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
   </serviceBehaviors>
  </behaviors>
 </system.serviceModel>

何が足りないの?

編集:私は問題を見つけたと思います - ルーティングサービスはサービスのためにこの構成を返していました -

<client>
   <endpoint address="http://shco-appsrv1.us.shepherd.ad:8781/ProcessManagementService/"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IProcessManagementService"
    contract="IProcessManagementService" name="WSHttpBinding_IProcessManagementService" />
   <endpoint address="http://shco-appsrv1.us.shepherd.ad:8781/ProcessManagementService/basic"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProcessManagementService"
    contract="IProcessManagementService" name="BasicHttpBinding_IProcessManagementService" />
 </client>

これは、外部サーバーではなく、内部サーバーを指します。これがルーティングサービスの標準的な動作であるかどうか、またはそれが過剰に運転可能な動作であるかどうかはわかりません。

役に立ちましたか?

解決

構成のServiceModelクライアント要素を適切に配線していないようです。 RoutingServiceは、標準のWCFサービスのように構成し、ルーティングされたサービスに「インターセプト」エンドポイントを公開する必要があります。次に、クライアント要素のエンドポイントを使用して、サービスコールをリダイレクトします。

以下は、コードに依存しない単純な構成です。これには、すべてをまっすぐに保つさまざまなルーティング値の命名規則が含まれています。構成内の「YourRoutedService」文字列を実際のサービス名に置き換えることができますが、すべてが正しく配線されたままにするためにサフィックスが残る必要があります。

ファイルベースの構成を正常に取得することから始めます(このアプローチで調整するときに再コンパイルは必要ありません)。次に、コードをファイル構成に基づいて、構成されているコードを削除します。

<system.serviceModel>
    <services
        name="System.ServiceModel.Routing.RoutingService"
        behaviorConfiguration="RoutingBehavior" >
        <endpoint
            name="RouterEndpoint"
            address=""
            binding="wsHttpBinding"
            bindingConfiguration="Http"
            contract="System.ServiceModel.Routing.IRequestReplyRouter" />

        <!-- List all endpoints to be routed via EndpointName routing filter -->
        <endpoint
            name="YourRoutedServiceName"
            address="YourRoutedService"
            contract="System.ServiceModel.Routing.IRequestReplyRouter"
            binding="wsHttpBinding"
            bindingConfiguration="Http" />
    </services>
    <routing>
        <filters>
            <!-- Active filters -->
            <filter
                name="YourRoutedServiceFilter"
                filterType="EndpointName"
                filterData="YourRoutedServiceName" />
        </filters>
        <filterTables>
            <filterTable name="WebLayer">
                <!-- Map to client Endpoints-->
                <add
                    filterName="YourRoutedServiceFilter"
                    endpointName="YourRoutedServiceNameEndpoint"
                    priority="0" />
            </filterTable>
        </filterTables>
    </routing>
    <behavior name="RoutingBehavior">
        <routing routeOnHeadersOnly="false" filterTableName="WebLayer" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceMetadata httpsGetEnabled="true"  />
    </behavior>
    <bindings>
        <wsHttpBinding>
            <binding name="Http">
                <security mode="None" />
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint
            name="YourRoutedServiceNameEndpoint"
            address="http://somehost/YourRoutedService/Service.svc"
            contract="*"
            binding="wsHttpBinding"
            bindingConfiguration="Http" />
    </client>
</system.serviceModel>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top