Trying to self-host, I get error - wcf service host cannot find any service metadata .. please check if metadata is enabled

回眸只為那壹抹淺笑 提交于 2021-01-27 19:21:51

问题


I am new to WCF and I've read answers to questions with titles similar to my error but I still cannot see what is wrong.

Following some other tutorials I decided to put my contract and my service in separate projects. Ultimately, I would like to host this in IIS but for now I just wanted to get the WCF Service Host to start (and WCF Test Client).

Here is the app.config in my service project (would this need to be in my contract project too I wonder??...):

<?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>

Here is the beginning of the FileService.cs file in my services project:

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()
    {

Finally, here is a bit of my IFileService.cs file in my contracts project:

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; }
    }
}
}

回答1:


The actual name of your service is BMI.TrimWCF.FileService.FileService (namespace BMI.TrimWCF.FileService, class name FileService). On the name attribute for the <service> tag you have only BMI.TrimWCF.FileService, so WCF can't find the configuration for your service. Please use the fully-qualified name of the service on the configuration, and WCF will then read it correctly.




回答2:


I will start a service with minimum configuration and then keep adding whatever needed. as with WCF 4 there default default binding and behavior configured by runtime.

1) service name in your config should be

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

2) I will change two tags (ServiceMetaData and ServiceDebug) as

3) you need not to include your app.config in your contracts project

4) Refernce your contractProjects in both service project and client project.



来源:https://stackoverflow.com/questions/7970995/trying-to-self-host-i-get-error-wcf-service-host-cannot-find-any-service-meta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!