2011-11-01 55 views
2

我是新来的WCF,我已阅读题目类似于我的错误,但我读了答案仍然看不出有什么问题。试图自我托管,我得到错误 - 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; } 
    } 
} 
} 

回答

3

服务的实际名称是BMI.TrimWCF.FileService.FileService空间(namespace BMI.TrimWCF.FileService,类名FileService)。在<service>标签的名称属性上,您只有BMI.TrimWCF.FileService,所以WCF找不到您的服务的配置。请使用配置上服务的完全限定名称,然后WCF将正确读取它。

+0

谢谢。我很接近。我完全按照你写的那样做,现在它工作。 –

1

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

在你的配置

1)服务的名称应该是

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

2)我会改变两个标签(ServiceMetaData和ServiceDebug)作为

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

4)引用服务项目和客户端项目中的contractProjects。