0

我一直在尝试将 XML 文件从我的 WCF 发送到我的项目,但运气不佳。一旦 WCF 完成响应并将其发送到电话,我的程序就会抛出异常。我希望有人可以帮助我,因为我一直在寻找答案,但一无所获。(该程序将 XNA 用于 Windows Phone 应用程序)

[System.Net.WebException]   {System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
   at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}  System.Net.WebException


public string EndHighScoreList(System.IAsyncResult result) {
                object[] _args = new object[0];
                string _result = ((string)(base.EndInvoke("HighScoreList", _args, result)));
                return _result;
            }

IService.cs

 [ServiceContract]
    [XmlSerializerFormat]
    public interface IService
    { 
        [OperationContract]
        void ParseScore(HighScore score);
        [OperationContract]
        string HighScoreList();
    }
    public class HighScore
    {
        [XmlElement]
        public UInt32 m_rank;
        [XmlAttribute]
        public string m_name;
        [XmlAttribute]
        public UInt32 m_score;
    }

服务.svc

public string HighScoreList()
        {

            XmlSerializer ser = new XmlSerializer(typeof(HighScore));
            using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("App_Data/Highscores.xml"), FileMode.OpenOrCreate))
            {
                return ser.Deserialize(fs).ToString();
            } 
        }

这是请求的代码

void globalRecieve(object obj, DodgeService.HighScoreListCompletedEventArgs e)
        {
            try
            {
                string result = e.Result;
                using (TextReader reader = new StringReader(result)){ 
                    XmlSerializer xml = new XmlSerializer(typeof(List<DodgeService.HighScore>));
                    foreach (DodgeService.HighScore sco in xml.Deserialize(reader) as List<DodgeService.HighScore>)
                        highScores.Add(sco); 
                } 
            }catch(Exception exception){
                string error = exception.Message;
            } 
        }


        protected override void Initialize()
        {
             service = new DodgeService.ServiceClient("BasicHttpBinding_IService");
        service.HighScoreListAsync(null);
        service.HighScoreListCompleted += new EventHandler<DodgeService.HighScoreListCompletedEventArgs>(globalRecieve);

            base.Initialize();
        }
4

3 回答 3

0

错误说:“未找到”。看起来该操作HighScoreList根本没有公开/可用。尝试在浏览器中打开路径。

于 2013-10-04T06:18:22.113 回答
0

Personally I believe WCF sucks. The Configuration alone is a nightmare and if you change anything, you have to re-build your objects and any changes you've made you have to re-make.

You should migrate to ServiceStack. It handles everything for you. You only write the sending and receiving of business DTO objects. Sending and receiving files is basic stuff for it,

See this google search for several people asking similar questions but based on ServiceStack. Mythz is a project lead for ServiceStack and he answers their questions. It should get you started and you should see how EASY it is.

Just for future reference in case that google search doesn't give the same as I got, here is the search and first three responses;

"servicestack file upload"

于 2013-10-03T17:47:04.313 回答
0

我一直有一个 Not Found 错误,因为然后 Windows Phone 运行它试图通过 LocalHost 连接到服务,这不起作用,因为我需要它来连接到开发 PC。解决方案是在服务器上托管 WCF 服务并连接到服务器或连接到开发 PC 的 IP。

于 2013-10-24T13:42:39.957 回答