0
WCF REST 서비스를 만들고 DI 컨테이너로 Autofac을 사용하려고합니다. 나는 서비스 클래스의 매개 변수화 된 생성자를 호출 할 수 있기를 원한다. 다음은 내 코드는 다음의 Global.asax에서 다음WCF 나머지에서 Autofac 생성자 주입을 트리거하는 방법?
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public partial class QDService:IQDService
{
public QDService(IApplicationService appService)
{
this.appService = appService;
}
private readonly IApplicationService appService;
}
, 나는 this chapter에 따라 설정을 설정 :
[WebInvoke(Method = "GET"
, ResponseFormat = WebMessageFormat.Xml
, BodyStyle = WebMessageBodyStyle.Bare
, UriTemplate = "/Test/{test}")]
public string Test(string test)
{
return "HelloWorld!";
}
: 아래
private void RegisterRoutes()
{
var builder = new ContainerBuilder();
builder.RegisterType<QDService>();
builder.RegisterType<ApplicationService>().As<IApplicationService>();
var container = builder.Build();
AutofacHostFactory.Container = container;
var factory = new AutofacWebServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute("QDService", factory, typeof(QDService)));
}
내가 전화거야하는 방법입니다 내가 프로젝트를 시작하고
http://localhost:1685/QDService/Test/1
로 이동 한 후
내가 매개 변수가있는 생성자를 제거한 후이 원인
내가 몰랐지만 : 브라우저 나에게 같은 예외가 던져
:
The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service.
, 나는 그것을 추적하기 위해 불을 지르고 사용이 발견 , 모두 잘 나를 위해 일했다. 그럼 나는 인터넷에서 빠른 검색을했지만 아무것도 얻지 못했다. 너의 도움이 필요해.
서비스를 디버깅했는데 생성자에서 중단되고 appService가 컨테이너에서 해결 되었습니까? –
@Jon_Lindeheim 페이지를 새로 고칠 때마다 디버그 지점이 트리거되지 않지만 위와 같은 예외가 발생합니다. – CharlieShi
net을 통해 exions를 검사했는데 요청에 일부 형식 오류가있는 것 같습니다. 하지만 자세한 내용을 확인하고 아무 것도 발견하지 못했습니다. – CharlieShi