2

私は WCF を初めて使用し、エラーに似たタイトルの質問への回答を読みましたが、何が問題なのかまだわかりません。

他のいくつかのチュートリアルに従って、コントラクトとサービスを別々のプロジェクトに入れることにしました。最終的には、IIS でこれをホストしたいと考えていますが、今のところは、WCF サービス ホスト (および WCF テスト クライアント) を開始することだけが目的でした。

これが私のサービスプロジェクトのapp.configです (これは私の契約プロジェクトにもある必要があるのでしょうか??...):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="CBMI.TrimWCF.FileService"
               behaviorConfiguration="Metadata">
        <endpoint address="ws" 
                  binding="wsHttpBinding" 
                  contract="CBMI.TrimWCF.FileServiceContract.IFileService">
        </endpoint>
        <endpoint name="mex" 
                  address="mex" 
                  binding="mexHttpBinding" 
                  contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8081/TrimWCFfileService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Metadata">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

私のサービスプロジェクトの FileService.cs ファイルの先頭は次のとおりです。

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.IO;
using System.Diagnostics;                       // needed for writing to EventLog.
using System.Text;                              // needed for StringBuilder
using System.ComponentModel;
using System.Web;                               // need to target .Net Framework 4.0 for the    project (for HttpContext)

using TRIMSDK;                                  // for TRIM 6.2. 7.1 (the "COM" SDK)
using CBMI.TrimWCF.Utilities;                   // separate project for misc classes
using CBMI.TrimWCF.FileServiceContract;
namespace CBMI.TrimWCF.FileService
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class FileService : IFileService
{
    Database db;
    string g_EventSource = "CBMI-TrimBroker";
    string g_EventLog = "Application";

    public FileService()
    {

最後に、契約プロジェクトの IFileService.cs ファイルの一部を次に示します。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace CBMI.TrimWCF.FileServiceContract
{
    [ServiceContract(Name = "IFileService", Namespace = "http://www.cbmiweb.com/TrimWCF/2011/11")]
    public interface IFileService
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

    [OperationContract]
    string DownloadFile(string trimURL
            , string TrimRecordNumber
            , string CallerPC
            , string RequestorID
            , out byte[] docContents
            , out string returnFiletype
            , out string returnFilename);
    [OperationContract]
    void DownloadFileCF(string trimURL
            , string TrimRecordNumber
            , string CallerPC = "not specified"
            , string RequestorID = "not specified");
    [OperationContract]
    string SearchCF(string trimURL
            , string CFSearchString
            , string CallerPC
            , string RequestorID);
    [OperationContract]
    string UploadFileCF(string trimURL
            , byte[] incomingArray
            , string fileName
            , string TrimRecordTypeName
            , string metaDataString);
    [OperationContract]
    string UpdateRecordCF(string trimURL
            , string TrimRecordNumber
            , string metaDataString);
}

[DataContract(Name = "WCFsample", Namespace = "http://www.cbmiweb.com/TrimWCF/2011/11 ")]
public class CompositeType
{
    bool boolValue = true;
    string stringValue = "Hello ";

    [DataMember]
    public bool BoolValue
    {
        get { return boolValue; }
        set { boolValue = value; }
    }

    [DataMember]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }
}
}
4

2 に答える 2

3

サービスの実際の名前はBMI.TrimWCF.FileService.FileService(namespace BMI.TrimWCF.FileService, class name FileService) です。<service>タグの name 属性には しかBMI.TrimWCF.FileServiceないため、WCF はサービスの構成を見つけることができません。構成でサービスの完全修飾名を使用してください。WCF はそれを正しく読み取ります。

于 2011-11-01T19:33:46.967 に答える
1

最小限の構成でサービスを開始し、必要なものを追加し続けます。WCF 4 と同様に、ランタイムによって構成された既定の既定のバインドと動作があります。

1)設定のサービス名は

 <service name="BMI.TrimWCF.FileService.FileService">

2) 2 つのタグ (ServiceMetaData と ServiceDebug) を次のように変更します。

3) コントラクト プロジェクトに app.config を含める必要はありません

4) サービス プロジェクトとクライアント プロジェクトの両方で contractProjects を参照します。

于 2011-11-01T19:56:51.167 に答える