0

I've been trying to send a XML file from my WCF to my project without much luck. I have a Exception thrown from my program once the response is completed by WCF and sent to the Phone. I was hoping someone could please help me, as I have been looking around for an answer and found nothing. (The program uses XNA for a Windows Phone Applications)

[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;
    }

Service.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();
            } 
        }

Here's the requested code

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();
        }
Joshua Waring
  • 619
  • 7
  • 23
  • 2
    _"I have a Exception thrown from my program"_ - please show it. – CodeCaster Oct 01 '13 at 10:21
  • An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.ni.dll but was not handled in user code – Joshua Waring Oct 01 '13 at 10:40
  • @JoshuaWaring well, there you go. Your solution is to handle that exception. – user1306322 Oct 01 '13 at 10:49
  • But what is the problem D: If I just randomly Catch and Ignore it will it still work? – Joshua Waring Oct 01 '13 at 10:51
  • No, don't randomly Catch! Catch where you call and then check the exception! For development you can add the exception details in the fault, if you want to see on the client what went wrong on the server. – flayn Oct 01 '13 at 11:21
  • It's in a event handler for when the data is returned, I've got a try there, but nothing is caught there. I've already got exceptionsDetailsInFaults turned on. – Joshua Waring Oct 01 '13 at 12:12
  • Post more exception details please and also post your client code where you have the try/catch block around your call. – flayn Oct 01 '13 at 14:51
  • There are your additional details – Joshua Waring Oct 01 '13 at 16:36
  • @JoshuaWaring Is there an InnerException? Can you post the whole Exception message, in its fullest? And by the way please remove `XNA` and `Windows` tags, this has nothing to do with it really. – user1306322 Oct 02 '13 at 01:54
  • Is there an Error with my line? new FileStream(HttpContext.Current.Server.MapPath("App_Data/Highscores.xml"), FileMode.OpenOrCreate) – Joshua Waring Oct 02 '13 at 04:13
  • I've changed it for Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "App_Data", "Highscores.xml") with the same problem – Joshua Waring Oct 02 '13 at 04:44

3 Answers3

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"

Community
  • 1
  • 1
Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
0

The error says: "NotFound". It looks like the operation HighScoreList is not exposed / available at all. Try opening the path in your browser.

flayn
  • 5,272
  • 4
  • 48
  • 69
  • I test the service with the WCF Test Client and everything works correctly, the results are as I expect them to be. It's just a issue when I use it inside the application where I get exceptions. So the Service is confirmed to work correctly, but not the application and I can't see why. – Joshua Waring Oct 07 '13 at 03:01
0

I kept having a Not Found error because, then the Windows Phone ran it was trying to connect to the service via LocalHost which wouldn't work as I needed it to connect to the development PC. The solution was to host the WCF service on a server and connect to the server or connect to the IP of the development PC.

Joshua Waring
  • 619
  • 7
  • 23