2

このサービスのURLにhttpリクエストを送信することで、他のアプリケーションが文字列を取得できるようにするWCFWebサービスを作成しようとしています。IISでサービスを公開しようとしましたが、URLを使用してサービスを参照しようとすると、次のように表示されます。

' The resource cannot be found'

URLを使用したフォルダへのパスを確認すると、エラーが発生します

'No protocol binding matches the given address 
'http://localhost:xxxx/WcfSampleLibrary/Service1/mex.' 
 Protocol bindings are configured at the Site level in IIS or WAS configuration'

公開されたフォルダのディレクトリパスは次のとおりです。

C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\WcfSampleLibrary.Service1
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\Web.config
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\bin\WcfSampleLibrary.dll

Web構成ファイル:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<system.web>
    <compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
  <service name="WcfSampleLibrary.Service1" behaviorConfiguration ="mex">
    <host>
      <baseAddresses>
        <add baseAddress = "http://192.xxx.x.xxx/WcfSampleLibrary/Service1/" />
      </baseAddresses>
    </host>
    <!-- Service Endpoints -->
    <endpoint address ="" 
      binding="wsHttpBinding"  contract="WcfSampleLibrary.IService1">
     <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <!-- Metadata Endpoints -->
   <endpoint address="http://localhost:xxxx/WcfSampleLibrary/Service1/mex" name="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mex">
     <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="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

4

1 に答える 1

3

IIS でホストされる WCF サービスでは、アドレスに完全な URI を指定しません。IIS がアドレスを決定します。また、baseAddressesIIS でホストする場合、この要素は完全に無視されます (Web.config から削除してください)。サービスのベース アドレスは、wcf サービスが配置されている Web サイトと仮想ディレクトリによって決まります。次のようにします。

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

アドレスはhttp://IIS.SERVER/SiteName/Folder/WcfSampleLibrary.Service1.svcになります。アドレスがわからない場合は、IIS 管理ツールを使用して、サービスが含まれているサイトを選択し、右クリックして [詳細設定] -> [サイトの参照] を選択します。

mexまた、 WSDL を公開したい場合は、あなたの動作で httpGetEnabled をオンにします。これにより、開発中のサービスを簡単に利用できるようになります。

<behaviors>
  <serviceBehaviors>
    <behavior name="mex" >
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

オンにhttpGetEnabledすると、サービス URI を参照すると、WSDL を表示するオプションが表示されます。

于 2012-04-27T13:53:12.347 に答える