0

WCF テスト クライアントを実行し、WCF サービスをローカルでデバッグすると、すべて正常に動作します。リモート サーバー上の IIS にデプロイし、WCF テスト クライアントでロードしようとすると、「オブジェクトがオブジェクトのインスタンスに設定されていません」というエラーが発生し始めます。サービスに try-catch を追加すると、エラーが「メソッドは許可されていません」に変わりました。

私はこれらのエラーを一日中読んでおり、ほとんどの投稿は、JSON または AJAX を使用して WCF クライアントにアクセスする人々に関するものです。提案された解決策の多くを試しましたが、そのほとんどは web.config への変更でした。この段階では、テスト クライアントを使用してアクセスしているだけです。機能することが証明されたら、Winform アプリケーションによって使用されます。

サービスで公開されている 2 つのメソッドは両方とも、異なるドメインの SQL サーバーへの接続を作成しますが、信頼が設定されています。これが問題の一部である可能性があると考えています。

マイ サービス インターフェイス

[ServiceContract]
public interface IMeterQueryService
{
    [OperationContract]
    List<Meter> FindMeter(string mprn);

実施サービス

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class MeterQueryService : IMeterQueryService
{
    public List<Meter> FindMeter(string mprn)
    {
        using (var da = new DataAccess())
        {

        var meters = da.GetMeter(mprn);
        da.Dispose();
        return meters;

        }
    }

アプリ構成ファイル

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

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <connectionStrings>
    <add name="Tims" connectionString="hidden" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="TimsAPI.MeterQueryService">
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false 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>
</configuration>

Web 構成ファイル、サイトは WCF サービス ライブラリを参照します。

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="false" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="TimsAPI.MeterQueryService">
        <endpoint address="http://easvr33:1000/" binding="basicHttpContextBinding" bindingConfiguration=""
          contract="TimsAPI.IMeterQueryService" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="localhost" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

アップデート

ライブラリではなく、WCF サービス Web サイトとして WCF サービスを再作成したところ、すべてが機能するようになりました。私が思うに、2つの設定ファイルの間に何か奇妙なことがあります。なぜそれが機能しなかったのか知りたいのですが、ソースに完全にアクセスできない人を診断するのは難しいかもしれないことも理解しています.

4

2 に答える 2

0

WCF サービスが IIS Web サイトを介してホストされている場合、サービスapp.configは使用されず、代わりにホスティング サイトweb.configが読み込まれます。サービスが機能するために必要なすべての設定web.configは、ホスティング サイトの に複製する必要があります。

于 2013-05-06T13:36:16.900 に答える
0

そもそもSVCの提供に問題がある可能性があります。ここから:

1.仮想ディレクトリのプロパティを開きます。

2.[ディレクトリ] タブに移動します。

3. [構成] をクリックします。

4.[追加...] をクリックします。</p>

5.次の情報を提供します。

a.実行可能ファイル: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

b.拡張子: .svc

c.動詞: GET、HEAD、POST、DEBUG

于 2013-05-03T21:30:49.623 に答える