gpt4 book ai didi

wcf - 将 WCF 与 Sharp 架构集成的问题

转载 作者:行者123 更新时间:2023-12-01 01:36:15 25 4
gpt4 key购买 nike

我正在使用一个使用 wcf 和清晰架构的应用程序,我正在尝试创建一个服务来写入数据库。这是我的服务:

[ServiceContract]
public interface IFacilitiesWcfService : ICloseableAndAbortable
{
[OperationContract]
void AddFacility(string facility);

}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
class FacilitiesWcfService:IFacilitiesWcfService
{
public FacilitiesWcfService(IRepositoryWithTypedId<Facility,string> facilityRepository)
{
Check.Require(facilityRepository != null, "facilityRepository may not be null");

this.facilityRepository = facilityRepository;
}
private readonly IRepositoryWithTypedId<Facility,string> facilityRepository;

public void AddFacility(string facility)
{
facilityRepository.DbContext.BeginTransaction();

Facility newFacility = new Facility();
newFacility.SetAssignedIdTo(facility);
newFacility.NAME=facility;
newFacility.ADDRESS = facility;

facilityRepository.DbContext.CommitTransaction();
}
public void Abort() { }

public void Close() { }
}

以及 web 项目中的 LogisticsWCF.svc 文件:
<%@ ServiceHost Language="C#" Debug="true" Service="Project.Wcf.FacilitiesWcfService"
Factory="SharpArch.Wcf.NHibernate.ServiceHostFactory, SharpArch.Wcf" %>

我用 svcutil.exe http://localhost:1905/LogisticsWCF.svc?wsdl 创建了一个客户端然后创建了这个测试用例:
[TestFixture]
class WCFLogisticsTests
{
[Test]
public void CanAddFacility()
{

FacilitiesWcfServiceClient facility = new FacilitiesWcfServiceClient();
facility.AddFacility("NEW");
facility.Close();
}
}

但我得到这个异常(exception):
TestCase 'Tests.Project.Web.WCFLogisticsTests.CanAddFacility'
failed: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail] : The needed dependency of type FacilitiesWcfService could not be located with the ServiceLocator. You'll need to register it with the Common Service Locator (CSL) via your IoC's CSL adapter.

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IFacilitiesWcfService.AddFacility(String facility)
C:\Documents and Settings\epena\My Documents\SVN\Project\tests\Project.Tests\FacilitiesWcfService.cs(58,0): at FacilitiesWcfServiceClient.AddFacility(String facility)
WCFLogisticsTests.cs(18,0): at Tests.Project.Web.WCFLogisticsTests.CanAddFacility()


0 passed, 1 failed, 0 skipped, took 4.52 seconds (NUnit 2.5.2).

我想我缺少一些尖锐架构的配置,因为当我不使用时 Factory="SharpArch.Wcf.NHibernate.ServiceHostFactory, SharpArch.Wcf"在 .svc 文件中,我没有收到异常,但我无法向数据库写入任何内容(我收到了 ISession 未配置异常)。

我试图遵循 Northwind 的例子,但它不起作用,我会错过什么?

最佳答案

最后我找到了答案,我在 ComponentRegistrar 中遗漏了以下行:

container.AddComponent("facilityWcfService", typeof(FacilitiesWcfService));

关于wcf - 将 WCF 与 Sharp 架构集成的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1836738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com