XNA Creators Club Online
Page 1 of 1 (10 items)
Sort Posts: Previous Next

using WCF?

Last post 2/25/2010 3:10 PM by Jim Perry. 9 replies.
  • 6/13/2009 4:11 AM

    using WCF?

    Is this possible? (this is for a windows game)

    I have a WCF prototype client and server console applications, that work fine.

    If I bring the client code into an (any) XNA 3 game, it times out when it tries to connect, the code is exactly the same. and I'm using the same App.config.

    I thought this would work, but something is up, can anyone offer suggestions or alternatives?
  • 6/13/2009 5:07 AM In reply to

    Re: using WCF?

    It is possible to use it in a windows game as it is just .Net code.

    My suggestion is to add some more debugging code to your application to see where it is upto when timing out.
  • 6/13/2009 4:06 PM In reply to

    Re: using WCF?

    There must be something exceedingly obvious I don't see, my code is exactly the same, the only difference is that in my XNA game the networking code files are in a folder (still with same namespace though) it compiles correctly.

    I am new to WCF and I am not sure how I would debug this,
    They are using the same Interface description project and the same server project as well as the same App.Config

    my console app:

    using System; 
    using System.Collections.Generic; 
    using System.Collections; 
     
    namespace WCF_Client 
        class Program 
        {  
            static void Main() 
            { 
                Console.WriteLine("Enter Username:"); 
                string username = Console.ReadLine(); 
                Console.WriteLine("Toybox Throwaway Networking Prototype WCF Client"); 
                Console.Write("Connecting to the server..."); 
                ToyBoxUser me = new ToyBoxUser(username); 
                ToyBoxServerConnection server = new ToyBoxServerConnection(me); 
                Console.WriteLine(" connected!"); 
                Console.Write("Authenticating... "); 
                server.Authenticate(); 
                Console.WriteLine(" done!"); 
                foreach(string s in server.ListRooms()) 
                { 
                    Console.WriteLine(s); 
                } 
     
                string msg; 
                 
                do { 
                    Console.WriteLine("Message:"); 
                    msg =  Console.ReadLine(); 
                    server.SendMessage(msg); 
                   
                } while (msg != "") ; 
     
                Console.WriteLine("Press [ENTER] to quit."); 
                Console.ReadLine(); 
                server.Disconnect(); 
            } 
        } 
     


    my Game1.cs (does not work), times out:

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using Microsoft.Xna.Framework; 
    using Microsoft.Xna.Framework.Audio; 
    using Microsoft.Xna.Framework.Content; 
    using Microsoft.Xna.Framework.GamerServices; 
    using Microsoft.Xna.Framework.Graphics; 
    using Microsoft.Xna.Framework.Input; 
    using Microsoft.Xna.Framework.Media; 
    using Microsoft.Xna.Framework.Net; 
    using Microsoft.Xna.Framework.Storage; 
     
    namespace WCF_Client 
        /// <summary> 
        /// This is the main type for your game 
        /// </summary> 
        public class Game1 : Microsoft.Xna.Framework.Game 
        { 
            GraphicsDeviceManager graphics; 
            SpriteBatch spriteBatch; 
     
     
            WCF_Client.ToyBoxUser user; 
            WCF_Client.ToyBoxServerConnection conn; 
     
            public Game1() 
            { 
                graphics = new GraphicsDeviceManager(this); 
                Content.RootDirectory = "Content"
            } 
     
            /// <summary> 
            /// Allows the game to perform any initialization it needs to before starting to run. 
            /// This is where it can query for any required services and load any non-graphic 
            /// related content.  Calling base.Initialize will enumerate through any components 
            /// and initialize them as well. 
            /// </summary> 
            protected override void Initialize() 
            { 
                // TODO: Add your initialization logic here 
                user = new WCF_Client.ToyBoxUser("toyfactory game"); 
                conn = new WCF_Client.ToyBoxServerConnection(user); 
                base.Initialize(); 
            } 
     
            /// <summary> 
            /// LoadContent will be called once per game and is the place to load 
            /// all of your content. 
            /// </summary> 
            protected override void LoadContent() 
            { 
                // Create a new SpriteBatch, which can be used to draw textures. 
                spriteBatch = new SpriteBatch(GraphicsDevice); 
                conn.Authenticate(); 
                conn.SendMessage("/j0"); 
                // TODO: use this.Content to load your game content here 
            } 
     
            /// <summary> 
            /// UnloadContent will be called once per game and is the place to unload 
            /// all content. 
            /// </summary> 
            protected override void UnloadContent() 
            { 
                // TODO: Unload any non ContentManager content here 
            } 
     
            /// <summary> 
            /// Allows the game to run logic such as updating the world, 
            /// checking for collisions, gathering input, and playing audio. 
            /// </summary> 
            /// <param name="gameTime">Provides a snapshot of timing values.</param> 
            protected override void Update(GameTime gameTime) 
            { 
                // Allows the game to exit 
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
                    this.Exit(); 
     
                // TODO: Add your update logic here 
     
                base.Update(gameTime); 
            } 
     
            /// <summary> 
            /// This is called when the game should draw itself. 
            /// </summary> 
            /// <param name="gameTime">Provides a snapshot of timing values.</param> 
            protected override void Draw(GameTime gameTime) 
            { 
                GraphicsDevice.Clear(Color.CornflowerBlue); 
     
                // TODO: Add your drawing code here 
     
                base.Draw(gameTime); 
            } 
        } 
     

  • 2/7/2010 3:11 AM In reply to

    Re: using WCF?

    Hi,

    Am planning on making a turn based game using WCF and XNA - was wondering if you resolved your issue?

    -LOK
  • 2/9/2010 4:07 AM In reply to

    Re: using WCF?

    There's an article on the CodeProject presenting an XNA game using WCF for networking...

  • 2/13/2010 8:01 PM In reply to

    Re: using WCF?

    Hi CaffeineAU! I was about to post a link to my XNA Snooker Club game, but I'm glad you posted the link first :-)

    Hi Verdant! When I was working on the XNA Snooker Club (http://www.codeproject.com/KB/game/XNASnookerClub.aspx), there were times when something weird happened, and the client couldn't communicate with the server. So I used the Svc Config Editor (to enable/configure tracing) along with the Svc Trace Viewer (to view the communication issues), so I found out the issues that were keeping the XNA client to communicate properly with the service.

    If you have doubts regarding how to use the Svc Config Editor and Svc Trace Viewer, please let me know.

    regards,
    marcelo
  • 2/25/2010 2:17 AM In reply to

    Re: using WCF?

    Is it possible for a XNA game on the XBox 360 to consume a WCF service?  I cannot seem to add a service reference when inside a XBox 360 game project.  Are there assembly references I need to add first?
  • 2/25/2010 5:03 AM In reply to

    Re: using WCF?

    No. You have no access to the internet from a 360.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 2/25/2010 2:19 PM In reply to

    Re: using WCF?

    That's odd, because I thought my XBox 360 had to access XBox Live over the Internet to check out my XNA Creators Club Premium Membership...

    However, technically, I'm not trying to access a WCF service across the web.  I'm trying to call a WCF service on my local home PC.

    Does XNA naturally support that or do I have to open a NetworkStream and send and receive SOAP messages programmatically?
  • 2/25/2010 3:10 PM In reply to

    Re: using WCF?

    No, you can't do that. The Framework pieces don't exist on the Xbox version of .NET to enable you to do it.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
Page 1 of 1 (10 items) Previous Next