我是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; }
}
}
}
答案 0 :(得分:3)
您的服务的实际名称是BMI.TrimWCF.FileService.FileService
(名称空间BMI.TrimWCF.FileService
,班级名称FileService
)。在<service>
标记的name属性上,您只有BMI.TrimWCF.FileService
,因此WCF无法找到您的服务的配置。请在配置中使用服务的完全限定名称,然后WCF将正确读取它。
答案 1 :(得分:1)
我将以最少的配置启动服务,然后继续添加所需的任何内容。 与WCF 4一样,默认情况下由运行时配置默认绑定和行为。
1)配置中的服务名称应为
<service name="BMI.TrimWCF.FileService.FileService">
2)我将两个标签(ServiceMetaData和ServiceDebug)更改为
3)您不需要在合同项目中包含app.config
4)在服务项目和客户项目中引用您的contractProject。