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>在您只有标签的名称属性上BMI.TrimWCF.FileService,因此 WCF 找不到您的服务的配置。请在配置中使用服务的完全限定名称,然后 WCF 将正确读取它。

于 2011-11-01T19:33:46.967 回答
1

我将以最低配置启动一项服务,然后继续添加所需的任何内容。与 WCF 4 一样,默认的默认绑定和行为由运行时配置。

1)您的配置中的服务名称应该是

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

2)我将两个标签(ServiceMetaData 和 ServiceDebug)更改为

3)你不需要在你的合同项目中包含你的 app.config

4) 在服务项目和客户项目中引用您的合同项目。

于 2011-11-01T19:56:51.167 回答