| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using System.ServiceModel;
- using System.Xml;
- namespace DopInterfacePlatform.Controllers
- {
- [ApiController]
- [Route("[controller]/[action]")]
- [Authorize]
- public class WeatherForecastController : ControllerBase
- {
- private static readonly string[] Summaries = new[]
- {
- "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
- };
- private readonly ILogger<WeatherForecastController> _logger;
- public WeatherForecastController(ILogger<WeatherForecastController> logger)
- {
- _logger = logger;
- }
- [HttpGet(Name = "GetWeatherForecast")]
- [Authorize]
- public IEnumerable<WeatherForecast> Get()
- {
- return Enumerable.Range(1, 5).Select(index => new WeatherForecast
- {
- Date = DateTime.Now.AddDays(index),
- TemperatureC = Random.Shared.Next(-20, 55),
- Summary = Summaries[Random.Shared.Next(Summaries.Length)]
- })
- .ToArray();
- }
- [HttpGet(Name = "GetByCount")]
- [Authorize]
- public int GetByCount(int count)
- {
- return count+7;
- }
- [HttpGet(Name = "GetByCount1")]
- [Authorize]
- public int GetByCount1(int count,int count2)
- {
- return count + 7+count2;
- }
- [HttpGet(Name = "TestWebservice")]
- [Authorize]
- public string TestWebservice()
- {
- var parameters = new Dictionary<string, string> { { "byProvinceName", "湖北" } };
- HttpContent httpContent = new FormUrlEncodedContent(parameters);
- // contentType对应 webservice提示 如下图
- httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
- HttpClient httpClient = new HttpClient();
- HttpResponseMessage response = httpClient.PostAsync("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getSupportCity", httpContent).Result;
- var statusCode = response.StatusCode.ToString();
- var result = response.Content.ReadAsStringAsync().Result;
- var doc = new XmlDocument();
- doc.LoadXml(result);
- // xml返回值数据所在标签,替换成你的xml结果标签,如下图
- var status = doc.InnerXml;
- return status;
- }
- }
- }
|