Programmatically configure InstanceContextMode
Existe uma maneira de fazer isso ...
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
... programaticamente?
O motivo é que desejo passar uma instância do meu serviço diretamente para a classe auxiliar auto-hospedada ao testar o serviç
Estou usando o Castle Windsor para criar todos os meus objetos, o que funciona bem ao usar o site de teste. Mas recebo o seguinte erro ao tentar usar minha classe auxiliar HttpWebService ...
System.InvalidOperationException was unhandled by user code
Message=In order to use one of the ServiceHost constructors that takes a service instance, the InstanceContextMode of the service must be set to InstanceContextMode.Single. This can be configured via the ServiceBehaviorAttribute. Otherwise, please consider using the ServiceHost constructors that take a Type argument.
Source=System.ServiceModel
Este é o construtor da minha classe auxiliar ...
public HttpWebService(string baseUri, string acceptType, TApi serviceInstance = null)
{
_baseUri = baseUri;
_acceptType = acceptType.ToLower();
_host = serviceInstance == null
? new HttpServiceHost(typeof (TApi), baseUri)
: new HttpServiceHost(serviceInstance, baseUri);
_host.Open();
_client = new HttpClient();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_acceptType));
}
ntão, eu preciso definir programaticamente oInstanceContextMode
quando no "modo de teste de integração", ou seja, na minha classe auxilia
Acho que preciso fazer algo assim ...
if (serviceInstance != null)
{
_host = new HttpServiceHost(serviceInstance, baseUri);
var whatDoIDoNow = null;
_host.Description.Behaviors.Add(whatDoIDoNow);
}
Qualquer ajuda / orientação seria ótima, pois estou realmente preso a iss