Этот вопрос напрямую связан с THIS QUESTION, но я понял, что предмет разный. Я бы начал новый вопрос по текущей проблеме. У меня есть служба WCF служба и графический интерфейс. GUI передает int в WCF, который должен укладывать его в List<int> IntList
; то в службе я хочу получить доступ к списку. проблема в том, что когда я пытаюсь добавить в список в службе WCF, я получаю предупреждение «Недоступный код обнаружено», а строка добавления полностью пропускается, когда я иду отлаживать ее. Как я могу получить этот список?«обнаруженный код недоступен», когда в службе WCF
ниже код WCF, ГИП вызов WCF и службы с помощью List<>
из WCF:
WCF:
[ServiceContract(Namespace = "http://CalcRAService")]
public interface ICalculator
{
[OperationContract]
int Add(int n1, int n2);
[OperationContract]
List<int> GetAllNumbers();
}
// Implement the ICalculator service contract in a service class.
public class CalculatorService : ICalculator
{
public List<int> m_myValues = new List<int>();
// Implement the ICalculator methods.
public int Add(int n1,int n2)
{
int result = n1 + n2;
return result;
m_myValues.Add(result);
}
public List<int> GetAllNumbers()
{
return m_myValues;
}
}
GUI:
private void button1_Click(object sender, EventArgs e)
{
using (ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/MyServiceAddress")))
{
ICalculator proxy = factory.CreateChannel();
int trouble = proxy.Add((int)NUD.Value,(int)NUD.Value);
}
}
Услуги:
protected override void OnStart(string[] args)
{
if (mHost != null)
{
mHost.Close();
}
mHost = new ServiceHost(typeof(CalculatorService), new Uri("net.pipe://localhost"));
mHost.AddServiceEndpoint(typeof(ICalculator), new NetNamedPipeBinding(), "MyServiceAddress");
mHost.Open();
using (ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/MyServiceAddress")))
{
ICalculator proxy = factory.CreateChannel();
BigList.AddRange(proxy.GetAllNumbers());
}
}
Я очень тупой ... конечно код косяк быть достигнуто после заявления о возвращении! – DarthSheldon
Eh no biggie. Живи и учись.. –