So I've created this web app that will make a call to a server to get information about branches, streams, changset info, etc. I'm working on creating the api using p4api.net.dll. I've downloaded and extracted it and followed the instruction on perforce page to get things connected to a server.
**Problem**
Using C# and P4API.NET, how to I create a basic program to connect and disconnect from the server?
**Solution**
The following code can be used as the foundation of a new P4API.NET program. To use and compile this code, follow these steps:
1. Download the zipped P4API.NET from the website(www.perforce.com) or the FTP site(ftp://ftp.perforce.com/perforce). Extract it into a local directory.
2. Open Visual Studio.
3. From the menu, select New->Project...
4. From the Visual C# section, select Console Application
5. Fill in the Name and Location as appropriate.
6. Click the OK Button.
7. Once the new project loads, right-click on the References in the Solution Explorer and select the option Add Reference... from the context menu.
8. Click on the Browse tab. Navigate to the folder where you extracted the P4API.NET zipfile, and go into the lib folder. Select p4api.net.dll (not p4bridge.dll) and click OK.
9. Cut and paste the code from below into the Program.cs file that was automatically created when you created the project, overwriting the default code.
10.Build the code by selecting Build -> Build Solution from the menu.
11.Open Windows Explorer. Navigate to the folder where you extracted the P4API.NET zipfile, and copy the p4bridge.dll file to the bin/Debug directory of your solution. You can set up the solution to copy it automatically, but it only needs to be done once.
12.Run the program with Debug -> Start Debugging
If you want to run the program outside Visual Studio, always make sure that the p4api.net.dll and p4bridge.dll files are included with the binary. The p4api.net.dll file contains the .NET assembly, while the p4bridge.dll contains the Perforce library.
Now, I skipped steps 3-6 and did the rest up until step 11. In my webapi project I do not have a bin/Debug folder. The only Debug folder I have is in an obj folder so I added it there. When I run my api I get the following image:
So far all I've tried to do is establish a connection using the following code:
string uri = "server:port";
string user = "username";
string ws_client = "ws_name";
Perforce.P4.Server server = new Perforce.P4.Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;
con.UserName = user;
con.Client = new Client();
con.Client.Name = ws_client;
con.Connect(null);
Can anyone help me out to fix this problem so I can at least get a connection started?