[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyPage : ContentPage
{
AuthenticationResult authResult;
private OrganizationDataWebServiceProxy proxy;
public MyPage()
{
InitializeComponent();
myButton.Clicked += MyButton_Clicked;
proxy = new OrganizationDataWebServiceProxy();
}
async void MyButton_Clicked(object sender, EventArgs args)
{
try
{
var auth = DependencyService.Get<IAuthenticator>();
authResult = await auth.Authenticate(Constants.Authority,
Constants.ServiceURL,
Constants.ClientId,
Constants.RedirectURL,
Constants.Username,
Constants.Password);
}
catch(Exception ex)
{
await DisplayAlert("Error", "This: " + ex, "got it");
}
proxy.ServiceUrl = Constants.ServiceURL;
proxy.AccessToken = authResult.AccessToken;
await GetLoggedInUserName();
}
public async Task GetLoggedInUserName()
{
try
{
WhoAmIResponse result = (WhoAmIResponse)await proxy.Execute(new WhoAmIRequest());
await DisplayAlert("Result n", "User Id : " + result.UserId.ToString() + "n OrganizationId: " + result.OrganizationId.ToString() + "n BusinessUnitId: " + result.BusinessUnitId.ToString(), "Ok", "Cancel");
}
catch (Exception ex)
{
await DisplayAlert("Error", "This: " + ex, "got it");
}
}
}
}
我收到此错误消息
1.当前文本中的名称LT不存在
2.当前文本中不存在名称AMP
3.当前文本中的名称GT不存在
4.authenticator是在给定上下文中无效的类型
有人请帮助我,我正要与Xamarin.forms一起制作CRM应用。Div>
该教程的作者由于HTML编码而在代码中存在一些错误,并且您复制了该错误。
更改线
var auth = DependencyService.Get<IAuthenticator>();
进入
var auth = DependencyService.Get<IAuthenticator>();