编译时出错-'无法将类型'string'隐式转换为'System.Uri' [英] Error when compiling - 'Cannot implicitly convert type 'string' to 'System.Uri'

查看:81
本文介绍了编译时出错-'无法将类型'string'隐式转换为'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,
            };
        }
            }

//在此处添加更多详细信息//添加越来越多的详细信息更多的详细信息

// adding more details here // adding more and more and more details more and details

//  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);
        }

//在此处添加更多详细信息//添加越来越多的详细信息更多的详细信息

// adding more details here // adding more and more and more details more and details

//  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此代码无法成功构建...***此问题是此代码未生成.*****

lplp this code is not successfully building... *** this issue is that this code is not building. *****

推荐答案

您知道您可以做到这一点:?

You know you can do this right : ?

Uri uri = new Uri(whateverstring);

这篇关于编译时出错-'无法将类型'string'隐式转换为'System.Uri'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆