4

以下の構成を使用して WCF サービスを実行するときに、VS2010 から WCF サービスを実行したい。

<system.serviceModel>
<services>
  <service name="WcfSample.Service1" behaviorConfiguration="servicebehaviour1">
    <endpoint  address ="http://localhost:8080/service1/Service1.svc" contract="WcfSample.IService1" binding="wsHttpBinding"></endpoint>
    <endpoint address="" binding="mexHttpBinding" contract ="IMetadataExchange"></endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="servicebehaviour1">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="false"/>
      <!-- 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="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />-->

以下のように例外が発生しています

指定されたアドレス 'http://localhost:8080/service1/Service1.svc' に一致するプロトコル バインディングはありません。プロトコル バインディングは、IIS または WAS 構成のサイト レベルで構成されます。

指定したアドレスで WCF を実行したい場合は、どうすればよいですか。

4

1 に答える 1

3

WCF サービスのホスティングは、構成ファイルのエンドポイントで定義したアドレスを取得しません

<endpoint 
      address="http://localhost:8080/service1/Service1.svce"

したがって、あなたが定義した上記のものは、これの代わりに正しいものではありません。以下のようにする必要があります

サービスのアドレスは、Web サーバーと仮想ディレクトリに加えて、以下のような SVC ファイル名です。

http://servername/vrirualdirectoryname/svcfiename.svc/

以下のように相対アドレスを定義できます。

<service name="WcfSample.Service1">
   <endpoint name="" 
             address="ServiceAddress" 
             binding="wsHttpBinding"   
             contract="WcfSample.IService1" />
</service>

最後に、サービスを消費するサービスアドレスは

http://servername/vrirualdirectoryname/svcfiename.svc/ServiceAddress

このように、アドレスを直接指定するのではなく、行うことができます。

ノート :

上記のコードは、サービスが IIS サーバーでホストされることを想定しています。

于 2013-01-12T08:49:50.993 に答える