0

いくつかの特定の要件のために、私は複数のサービスバージョンに単一のsvcを使用する必要があります。異なる名前空間を使用して、バージョンごとにインターフェイスコントラクトを分離しました。すべてのサービスバージョンを実装するクラス(部分的)は1つだけです。

私のコードは以下の通りです:

namespace Application.V1
{
[ServiceContract(Namespace = "http://google.com/ApplicationService/v1.0", Name = "IMathService")]
public interface IMathService
}

namespace Application.V2
{
[ServiceContract(Namespace = "http://google.com/ApplicationService/v2.0", Name = "IMathService")]
public interface IMathService
}

Application / MathServiceV1.csファイル:

public partial class MathService : V1.IMathService { }

Application / MathServiceV2.csファイル:

public partial class MathService : V2.IMathService { }

Application / MathService.csファイル:

public partial class MathService {}

サービスweb.configに以下を追加しました。

  <service behaviorConfiguration="ServiceBehavior" name="Application.MathService">
    <endpoint address="V1" binding="wsHttpBinding" contract="Application.V1.IMathService" />
    <endpoint address="V2" binding="wsHttpBinding" contract="Application.V2.IMathService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

MathService.svc次のファイルがあります。

<%@ ServiceHost Service="Application.MathService, Application"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"%>

アドレスを使用してプロキシを生成するとhttp://localhost:8000/MathService.svc、クライアントエンドポイントは次のように生成されます。

    <client>
        <endpoint address="http://localhost:8000/MathService.svc/V1"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMathService"
            contract="MathService.IMathService" name="WSHttpBinding_IMathService">
        </endpoint>
        <endpoint address="http://localhost:8000/MathService.svc/V2"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMathService1"
            contract="MathService.IMathService1" name="WSHttpBinding_IMathService1">
        </endpoint>
    </client>

私の懸念は、クライアントエンドポイントアドレスがで生成されることですMathService.svc/V1が、見たいV1/MathService.svcです。

アドレスを指定してサービスを参照すると、エラーhttp://localhost:8000/MathService.svc/V1が発生しHTTP 400 Bad Requestます。

助言がありますか?

4

1 に答える 1

1

400 bad request エラーについて - おそらく MEX が有効になっていないため、ペイロードなしでリクエストを行うことはサービスにとって意味がありません。

MEX の有効化に関する質問は次のとおりです。 WCF メタデータを有効にする方法は? MEX を有効にするか、適切なサービス コンシューマーを使用してサービスを呼び出します。

アドレス指定に関しては、WCF だけでやりたいことを行うことはできません。IIS でホストされている WCF を使用しているため (SVC ファイルを使用しているため、これを想定しています)、HTTP 要求は SVC ファイルの場所に送信する必要があり、その後 (/V1 など) を使用して適切なファイルを見つけます。終点。これが IIS での動作です。ファイル名 (MathService.asmx) の前に /v1/ を置くと、IIS は /v1/ という名前のフォルダーを探してから、MathService.asmx という名前のファイルを見つけようとします。

ただし、Web.config に URL リライターをインストールして、優先 URI を上記のものにリダイレクトできる場合があります。asp.net での Url の書き換えに関するドキュメントを次に示し ます。

于 2012-10-09T03:21:14.153 に答える