메서드 Final()에 문제가 있습니다. 그것은 IWeather의 목록을 반환해야하지만 내가 그것을 호출하면 null을 반환합니다. 디버그에서 나는WCF 서비스의 메서드는 아무 것도 반환하지 않습니다.
return this.returner;
에서 중지하지만, 항상 null이고 MainMethod는() "마무리"와 목록 "기 returner"를 반환하기 때문에 널 (null)이 아닌 이유 디버그() MainMethod에있을 때 나도 몰라. 클래스의 새로운 인스턴스가 WCF 요청이 때마다 만들어지기 때문에
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using LibW;
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AllInOne
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
[DataMember]
private List<LibW.IWeather> returner = new List<LibW.IWeather>();
/// <summary>
/// method set connection to google and get xml document weather for there
/// </summary>
/// <param name="city">city for which find weather</param>
/// <param name="lang">lang of text</param>
/// <returns>return either "finish if all successful or Exception msg or errors with city finding and error with connection</returns>
[OperationContract]
public string MainMethod(string city, string lang)
{
//check connection
Ping p = new Ping();
PingReply pr = p.Send(@"google.com");
IPStatus status = pr.Status;
if (status != IPStatus.Success)
return "Error with Connection";
//try tp get xml weather
try
{
XElement el;
HttpWebRequest req =
(HttpWebRequest) WebRequest.Create("http://www.google.com/ig/api?weather=" + city + "&hl=" + lang);
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
StringBuilder sb = new StringBuilder();
using (StreamReader streamreader = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding(1251)))
{
el = XElement.Load(streamreader);
}
int addv = 0;
var v = from c in el.Elements()
select c;
//I get here data from XML(condition,temperature and etc.)
return "finish";
}
catch (Exception exc)
{
return exc.Message;
}
}
/// <summary>
/// return list of weather fot 4 days
/// </summary>
/// <returns>list</returns>
[OperationContract]
public List<IWeather> Final()
{
return this.returner;
}
}
'returner'가'null'이라고 말하면, 실제로'null'을 의미합니까, 아니면 빈'List <>'입니까? –