Trying to establish a connection in xamarin VS 2019 - xamarin

I’m trying to establish a connection with a Web Service already running with Visual Studio 2019 community. The connection is already establish on Visual Studio but when trying to use it I got CS0119 error ‘UsuariosSoap’ is a type, which is not valid int given context.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Net;
using UsuarioWS;
namespace XamarinWSMobile
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void AnadirUsuario(object sender, EventArgs e)
{
//establece la conexion con el web service
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
usuarioWS.GuardarUsuarioAsync(this.Nombre.Text, this.Apellidos.Text,this.Direccion.Text, this.Pueblo.Text, this.ZipCode.Text, this.FechaNac.Text);
}
}
}

That error is telling UsuariosSoap is a Type so this is wrong:
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
In order to use it, you need to create an instance of the service, the UsuariosSoap class, before using it.
Replace the line above with this:
UsuarioWS.UsuariosSoap usuarioWS = new UsuarioWS.UsuariosSoap();
Hope this helps.-

Related

how to connect to oracle 10g using visual studio 2013

I am new to oracle database, so i wanted to know how i can connect to an oracle 10g database using visual studio 2013.
Well i went to the server explorer and add connection where i chose the data source as Oracle Database and the data provider as .NET Framework Data Provider for OLE DB.
After that on testing the connection i get the error message as-
ORA-06413: Connection not open.
I searched a lot but couldn't find a proper answer to this question..
Can somebody help me out please.
OK so this is what I have done till now-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Hostel_Management_System
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_login_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Data Source=localhost;Initial Catalog=XE;Provider=SQLOLEDB;user-name=system;password=mypassword");
con.Open();
MessageBox.Show(con.State);
}
}
}
And I am getting a System.Data.OleDb.OleDbException in System.Data.dll.
Is this of any help??
[1]. http://i.stack.imgur.com/KUlZc.png
AFAIK the best way to create .net apps connected to Oracle is to use ODP.net and more specifically the managed driver which is available here.
The managed driver allows you to avoid installing an Oracle client on the machine your app runs on.
Sample code partially from the Oracle website:
using System;
using System.Data;
using Oracle.ManagedDataAccess.Client;
using System.Configuration;
class OracleConnectionSample
{
static void Main()
{
// Connect
const string connectionStringName = ...
string constr = ConfigurationManager.ConnectionStrings[connectionStringName].
ConnectionString;
using (var con = new OracleConnection(constr))
{
con.Open();
// Execute a SQL SELECT
using (OracleCommand cmd = con.CreateCommand())
{
cmd.CommandText = "select * from emp";
OracleDataReader reader = cmd.ExecuteReader();
// Print all employee numbers
while (reader.Read())
{
Console.WriteLine(reader.GetInt32(0));
}
}
}
}
}

Accessing Office Clip Board using C#.net

I use Visual Studio 2005 to develop a "Windows Service" using c#.net. My code requires to access the MS office Clipboard. But on trying to access the Clipboard class, the debugger throws an error
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."
during the run-time. On checking for the solutions, I found that this could be solved by adding "[STAThread]" before the main method. But on adding this, I get a compilation error
"The type or namespace name 'STAThread' could not be found (are you missing a using directive or an assembly reference?)"
Is it possible to access the clipboard with my current version of .NET(.NET 3.0)?
The main method is in a file titled "program.cs" and the logic is in a file titled "Service.cs". Clipboard is used by Service.cs.
/* Program.cs */
using System.Collections.Generic;
using System.ServiceProcess;
using System.Text;
using System.Media;
using System.Threading;
namespace WindowsService1
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
#if DEBUG
Service1 serv = new Service1();
serv.onDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service1() };
ServiceBase.Run(ServicesToRun);
#endif
}
}
}
/* Service.cs */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Timers;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public void onDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
clear_cb();
}
protected void clear_cb()
{
Clipboard.Clear(); // This is the line where I get the exception
}
protected override void OnStop()
{
// TODO: To clear the back up Database
}
}
}

Trying to play sound effects using XNA

I'm writing my first app for windows phone, which will be a sound board, using XNa's soundeffect object.
The project is a Windows phone Silverlight and Xna Application c#
I got some sample code from the book, 101 phone 7 apps.
The linbe to load in the sound gives me a
"the type StreamResourceInfo namespace could not be found"
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Audio;
namespace SlXnaApp4
{
public partial class MainPage : PhoneApplicationPage
{
SoundEffect cowbell;
// Constructor
public MainPage()
{
// Load sound file
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
// create xna sound
cowbell = SoundEffect.FromStream(info);
// Sub to per frame call back
CompositionTarget.Rendering += CompositionTarget_Rendering;
// requred for xna sound effects to work
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
// testb sound
cowbell.Play();
InitializeComponent();
}
void CompositionTarget_Rendering(object sender, EventArgs e)
{
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
}
// Simple button Click event handler to take us to the second page
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
}
}
}
Add a using directive for System.Windows.Resources:
using System.Windows.Resources;

name 'application' does not exist in the current context

Hi I'm working to develop a solution to creating a toolbar in Outlook 2010 using VSTO 2012 and the microsoft outlook 2010 addin. In a nutshell I am able to create the Outlook ribbon and a button but I am unable to get the button to open an .oft file. In Visual Studio I get the following error "The name 'application' does not exist in the current context". I have added a reference to the Microsoft Office 14.0 Object Library also. Below is the code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn8
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void CreateItemFromTemplate()
{
Outlook.Folder folder =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"c:\ivy.oft", folder) as Outlook.MailItem;
mail.Subject = "Congratulations";
mail.Save();
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
}
}
}
Thanks any help is appreciated it is probably something simple thats been missed.
An instance of Application can be accessed using Globals.ThisAddIn.Application. If you renamed your AddIn class to something different e.g. MyAddIn then the command will be: Globals.MyAddIn.Application.
Here is a link with more details: http://msdn.microsoft.com/en-us/library/vstudio/bb157876(v=vs.100).aspx
Finally got there in the end, heres the code.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn3
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application Application = Globals.ThisAddIn.Application;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"Z:\Transfer\Outlook 2010 Templates\testsubject.oft") as Outlook.MailItem;
mail.Display(true);
}

Tilting web browser on windows phone 7

i'm working on a windows phone 7 emulator. I have a web browser which navigates to local host. So my problem i faced was that when i tilt the windows phone 7 emulator 90% right, the screen doesn't. Could there be any advice on how to do so?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace DSP
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("Loading website. This might take a few seconds...");
webBrowser1.Navigate(new Uri("http://localhost/Liweiyi_fyp_082648y/homepage.html", UriKind.Absolute));
}
private void webBrowser1_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
Check your SupportedOrientations is PortraitOrLandscape in your xaml.
Also check your emulator isn't orientation locked due to hardware keybaord emulation. Restart it if you're not sure how to fix that.
I believe you're looking for how to handle orientation changes on the phone?
You're looking to change the following in the .xaml for the appropriate page - most likely MainPage.xaml:
Change the highlighted line to read
SupportedOrientations="PortraitOrLandscape"
And in case that wasn't enough information, here's a helpful blogpost.

Resources