문제

WCF와 Sharp Architecture를 사용하는 응용 프로그램으로 작업하고 있으며 데이터베이스에 쓸 수있는 서비스를 작성하려고합니다. 내 서비스는 다음과 같습니다.

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

웹 프로젝트의 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();
    }
}

그러나 나는이 예외를 얻는다 :

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 예제를 따르려고했지만 작동하지 않습니다. 무엇을 놓칠 수 있습니까?

도움이 되었습니까?

해결책

마지막으로 답을 찾았습니다. 구성 요소 레지스트라에서 다음 줄이 누락되었습니다.

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

다른 팁

서비스 방법에서 아무것도 반환하지 않으므로 isoneway = true로 표시해야합니다.

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

}

기본적으로 WCF는 요청/응답을 기대합니다. 즉, 서비스 방법에서 응답을 다시 얻을 것으로 예상됩니다. "void"는 응답으로 계산되지 않으므로 아무것도 반환하지 않는 서비스 방법을 표시합니다. IsOneWay=true 그리고 당신은 괜찮을 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top