编译时出错 - '无法将类型 'string' 隐式转换为 'System.Uri'
Error when compiling - 'Cannot implicitly convert type 'string' to 'System.Uri'
HI I am getting this error when compiling in the beginning at SMS.Rest.Client. We are trying to use the Celltrust SMS server to facilitate messaging in our app. -------------------------END____________-
using Lda.Sms.Client.Events;
using Lda.Sms.Models;
using Caliburn.Micro;
using Newtonsoft.Json;
using RestSharp;
using RestSharp.Deserializers;
using RestSharp.Serializers;
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
------------------------------
namespace Lda.Sms.Client.Services {
public class SmsRestClient : ISmsRestClient, IHandle<SuccessfulLoginEvent> {
private RestClient client = new RestClient();
string userId = null;
public SmsRestClient(IEventAggregator eventAggregator) {
eventAggregator.Subscribe(this);
var address = ConfigurationManager.AppSettings["serverAddress"];
client.BaseUrl = address + "api";
client.AddHandler("application/json", new JsonNetSerializer());
}
public void Handle(SuccessfulLoginEvent message) {
if (client.CookieContainer == null) {
client.CookieContainer = new System.Net.CookieContainer();
}
client.CookieContainer.Add(message.AuthenticationCookie);
userId = message.UserId;
}
---------------------------------------------
#region Asynchronous Api
public async Task<Settings> GetSettingsAsync() {
return (await client.ExecuteTaskAsync<Settings>(CreateGetSettingsRequest())).Data;
}
public async Task<User> GetUserAsync() {
return (await client.ExecuteTaskAsync<User>(CreateGetUserRequest())).Data;
}
public async Task UpdateSettingsAsync(Settings settings) {
var response = await client.ExecuteTaskAsync(CreateUpdateSettingsRequest(settings));
return;
}
public async Task SendMessageAsync(int contactId, string body) {
var response = await client.ExecuteTaskAsync(CreateSendMessageRequest(contactId, body));
return;
}
#endregion Asynchronous Api
#region Synchronous Api
public Settings GetSettings() {
return client.Execute<Settings>(CreateGetSettingsRequest()).Data;
}
public User GetUser() {
return client.Execute<User>(CreateGetUserRequest()).Data;
}
public void SendMessage(int contactId, string body) {
client.Execute(CreateSendMessageRequest(contactId, body));
}
public void UpdateSettings(Settings settings) {
client.Execute(CreateUpdateSettingsRequest(settings));
}
#endregion Synchronous Api
#region Rest Requests
private RestRequest CreateGetSettingsRequest() {
return new RestRequest {
Resource = "Settings",
Method = Method.GET
};
}
private RestRequest CreateGetUserRequest() {
var request = new RestRequest {
Resource = "User/{userId}",
Method = Method.GET
};
request.AddUrlSegment("userId", userId);
return request;
}
private RestRequest CreateUpdateSettingsRequest(Settings settings) {
var request = new RestRequest {
JsonSerializer = new JsonNetSerializer(),
Resource = "Settings",
Method = Method.POST,
RequestFormat = DataFormat.Json
};
request.AddBody(settings);
return request;
}
private RestRequest CreateSendMessageRequest(int contactId, string body) {
var request = new RestRequest {
Resource = "Sms",
Method = Method.POST,
};
request.AddParameter("contactId", contactId, ParameterType.QueryString);
request.AddParameter("body", body, ParameterType.QueryString);
return request;
}
#endregion Rest Requests
}
internal class JsonNetSerializer : IDeserializer, ISerializer {
private Newtonsoft.Json.JsonSerializer _serializer;
public JsonNetSerializer() {
ContentType = "application/json";
_serializer = new Newtonsoft.Json.JsonSerializer {
MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Include,
DefaultValueHandling = DefaultValueHandling.Include,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
};
}
}
// 在此处添加更多详细信息
// 添加越来越多的细节和细节
// Asher barah Sasone viSimcha sasone vi Simchas Chason Vi Kalah
// mnnm
public string ContentType { get; set; }
public string DateFormat { get; set; }
public string Namespace { get; set; }
public string RootElement { get; set; }
public T Deserialize<T>(IRestResponse response) {
using (var textReader = new StreamReader(new MemoryStream(response.RawBytes)))
using (var jsonTextReader = new JsonTextReader(textReader))
return _serializer.Deserialize<T>(jsonTextReader);
}
// 在此处添加更多详细信息
// 添加越来越多的细节和细节
// Asher barah Sasone viSimcha sasone vi Simchas Chason Vi Kalah
// mnnm
// details detail;s and detail;s
public string Serialize(object obj) {
using (var textWriter = new StringWriter())
using (var jsonTextWriter = new JsonTextWriter(textWriter)) {
jsonTextWriter.Formatting = Formatting.Indented;
jsonTextWriter.QuoteChar = '"';
_serializer.Serialize(jsonTextWriter, obj);
return textWriter.ToString();
}
}
}
}
lplp
此代码未成功构建...
*** 此问题是此代码未构建。 *****
你知道你可以做到这一点: ?
Uri uri = new Uri(whateverstring);
HI I am getting this error when compiling in the beginning at SMS.Rest.Client. We are trying to use the Celltrust SMS server to facilitate messaging in our app. -------------------------END____________-
using Lda.Sms.Client.Events;
using Lda.Sms.Models;
using Caliburn.Micro;
using Newtonsoft.Json;
using RestSharp;
using RestSharp.Deserializers;
using RestSharp.Serializers;
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
------------------------------
namespace Lda.Sms.Client.Services {
public class SmsRestClient : ISmsRestClient, IHandle<SuccessfulLoginEvent> {
private RestClient client = new RestClient();
string userId = null;
public SmsRestClient(IEventAggregator eventAggregator) {
eventAggregator.Subscribe(this);
var address = ConfigurationManager.AppSettings["serverAddress"];
client.BaseUrl = address + "api";
client.AddHandler("application/json", new JsonNetSerializer());
}
public void Handle(SuccessfulLoginEvent message) {
if (client.CookieContainer == null) {
client.CookieContainer = new System.Net.CookieContainer();
}
client.CookieContainer.Add(message.AuthenticationCookie);
userId = message.UserId;
}
---------------------------------------------
#region Asynchronous Api
public async Task<Settings> GetSettingsAsync() {
return (await client.ExecuteTaskAsync<Settings>(CreateGetSettingsRequest())).Data;
}
public async Task<User> GetUserAsync() {
return (await client.ExecuteTaskAsync<User>(CreateGetUserRequest())).Data;
}
public async Task UpdateSettingsAsync(Settings settings) {
var response = await client.ExecuteTaskAsync(CreateUpdateSettingsRequest(settings));
return;
}
public async Task SendMessageAsync(int contactId, string body) {
var response = await client.ExecuteTaskAsync(CreateSendMessageRequest(contactId, body));
return;
}
#endregion Asynchronous Api
#region Synchronous Api
public Settings GetSettings() {
return client.Execute<Settings>(CreateGetSettingsRequest()).Data;
}
public User GetUser() {
return client.Execute<User>(CreateGetUserRequest()).Data;
}
public void SendMessage(int contactId, string body) {
client.Execute(CreateSendMessageRequest(contactId, body));
}
public void UpdateSettings(Settings settings) {
client.Execute(CreateUpdateSettingsRequest(settings));
}
#endregion Synchronous Api
#region Rest Requests
private RestRequest CreateGetSettingsRequest() {
return new RestRequest {
Resource = "Settings",
Method = Method.GET
};
}
private RestRequest CreateGetUserRequest() {
var request = new RestRequest {
Resource = "User/{userId}",
Method = Method.GET
};
request.AddUrlSegment("userId", userId);
return request;
}
private RestRequest CreateUpdateSettingsRequest(Settings settings) {
var request = new RestRequest {
JsonSerializer = new JsonNetSerializer(),
Resource = "Settings",
Method = Method.POST,
RequestFormat = DataFormat.Json
};
request.AddBody(settings);
return request;
}
private RestRequest CreateSendMessageRequest(int contactId, string body) {
var request = new RestRequest {
Resource = "Sms",
Method = Method.POST,
};
request.AddParameter("contactId", contactId, ParameterType.QueryString);
request.AddParameter("body", body, ParameterType.QueryString);
return request;
}
#endregion Rest Requests
}
internal class JsonNetSerializer : IDeserializer, ISerializer {
private Newtonsoft.Json.JsonSerializer _serializer;
public JsonNetSerializer() {
ContentType = "application/json";
_serializer = new Newtonsoft.Json.JsonSerializer {
MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Include,
DefaultValueHandling = DefaultValueHandling.Include,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
};
}
}
// 在此处添加更多详细信息 // 添加越来越多的细节和细节
// Asher barah Sasone viSimcha sasone vi Simchas Chason Vi Kalah
// mnnm
public string ContentType { get; set; }
public string DateFormat { get; set; }
public string Namespace { get; set; }
public string RootElement { get; set; }
public T Deserialize<T>(IRestResponse response) {
using (var textReader = new StreamReader(new MemoryStream(response.RawBytes)))
using (var jsonTextReader = new JsonTextReader(textReader))
return _serializer.Deserialize<T>(jsonTextReader);
}
// 在此处添加更多详细信息 // 添加越来越多的细节和细节
// Asher barah Sasone viSimcha sasone vi Simchas Chason Vi Kalah
// mnnm
// details detail;s and detail;s
public string Serialize(object obj) {
using (var textWriter = new StringWriter())
using (var jsonTextWriter = new JsonTextWriter(textWriter)) {
jsonTextWriter.Formatting = Formatting.Indented;
jsonTextWriter.QuoteChar = '"';
_serializer.Serialize(jsonTextWriter, obj);
return textWriter.ToString();
}
}
}
}
lplp 此代码未成功构建... *** 此问题是此代码未构建。 *****
你知道你可以做到这一点: ?
Uri uri = new Uri(whateverstring);