尝试自托管,我收到错误 - wcf 服务主机找不到任何服务元数据.. 请检查元数据是否已启用 [英] Trying to self-host, I get error - wcf service host cannot find any service metadata .. please check if metadata is enabled
问题描述
我是 WCF 的新手,我已经阅读了标题与我的错误类似的问题的答案,但我仍然看不出哪里出了问题.
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.
根据其他一些教程,我决定将我的合同和我的服务放在不同的项目中.最终,我想在 IIS 中托管它,但现在我只想启动 WCF 服务主机(和 WCF 测试客户端).
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).
这是我服务项目中的app.config(我想知道这是否也需要在我的合同项目中??...):
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>
这是我的服务项目中 FileService.cs 文件的开头:
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()
{
最后,这是我的合同项目中的一些 IFileService.cs 文件:
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; }
}
}
}
推荐答案
您的服务的实际名称是 BMI.TrimWCF.FileService.FileService
(命名空间 BMI.TrimWCF.FileService
code>,类名 FileService
).在
标记的 name 属性上,您只有 BMI.TrimWCF.FileService
,因此 WCF 找不到您的服务的配置.请在配置上使用服务的完全限定名称,然后 WCF 将正确读取它.
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.
这篇关于尝试自托管,我收到错误 - wcf 服务主机找不到任何服务元数据.. 请检查元数据是否已启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!