C# connect and login to webservice of betfair.com (newbie)
I am trying to connect to the following betfair.com web service. https://api.betfair.com/global/v3/BFGlobalService.wsdl
Basi开发者_StackOverflowcally, I just want to log in and display this information in the console window.I did this with PHP and it was so easy, but I am new to C# and am having trouble starting off.
Basically, I want to login and display the session token received from the web service on the screen.I added the web service reference to the solution in visual studio .net 2010. In PHP we just had one request to make to the web service and it would return the data as an object. But it seems like in C#, I have to make 2 calls, Request and Response? Is this right?
Sorry, Im a newbie to c#, but I see great potential with the language, I really need some basic guidance as to how to proceed.
Currently, I have added the web service to my solution, What are the most basic things I have to do in order to login and receive a session token.
More Information about the Betfair Web Service can be found here:
http://bdp.betfair.com/index.php?option=com_weblinks&catid=59&Itemid=113I tried looking through the example applications provided through betfair, but they are so complex, I just want the simplest way to Consume a webservice and login to retrieve a session token.
Thanks
EDIT
I was tryng something like this.class Program
{
public static string username = "username";
public static string password = "password";
public static int softwareId = 82;
public static int productId = 0;
private static BFGlobalService m_globalService;
static void Main(string[] args)
{
m_globalService = new BFGlobalService();
}
static void Login()
{
LoginReq req = new LoginReq();
req.username = username;
req.password = password;
req.productId = productId;
req.vendorSoftwareId=softwareId;
LoginResp resp = m_globalService.login(req);
Console.WriteLine(resp.minorErrorCode);
Console.ReadKey();
}
}
But Im a noob so I dont even know if this is right!!
Any help to get me off my feet would be great!!, Plus a simple explanation if anything to complex.
Thanks!!
EDIT: Solution I had to replace these 4 lines at the end.
string st = resp.errorCode.ToString();
string sessTok = resp.header.sessionToken;
Console.WriteLine(st + " " + sessTok);
Console.ReadKey();
You might want to download this app. http://forum.bdp.betfair.com/attachment.php?s=18f39758fa8c2e850b27cf2d524903ed&attachmentid=20&d=1235565908
Its a reference implementation from Betfair in C#.
It is a really good foundation to start off with. It has logins, async calls implementation and navigation of the different markets as well as how to place bets. I extended it myself it really is very good
You're never calling your Login method. Try this:
static void Main(string[] args)
{
m_globalService = new BFGlobalService();
Login(); // calling your login method here...
}
Also: I'm not familiar with that API but I bet you're missing an initialization call between creating the BFGlobalService object and calling its Login method.
Here are a few pointers to get going with C#:
- Make use of properties rather than public variables
- Use try/catch exception handling on your web service calls
- Try to not do too much work in your Main function. (I know you're just getting started but it's good to practice doing things the right way.) You should have a separate class that Main instantiates and invokes to initiate your web service interaction.
精彩评论