Netcore webservice
程序员文章站
2023-12-28 13:41:58
...
using System;
using System.Text;
using System.Net;
using System.Net.Http;
using System.IO;
namespace WebSeviceTest
{
class Program
{
private static string head = "<?xml version =\"1.0\" encoding=\"utf-8\"?>";
private static string P1 = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetProductionData xmlns=\"http://tempuri.org/\">";
private static string end = "</GetProductionData></soap:Body></soap:Envelope>";
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
GetData("74100001", "2019-03-01", "2019-04-01");
}
private static string GetData(string weeks,string pstart,string pend)
{
string rsp = "";
try
{
StringBuilder sb = new StringBuilder();
sb.Append(head);
sb.Append(P1);
sb.AppendFormat("<AA>{0}</AA>", weeks);
sb.AppendFormat("<BB>{0}</BB>", pstart);
sb.AppendFormat("<CC>{0}</CC>", pend);
sb.Append(end);
Uri uri = new Uri("http://127.0.0.1/xxx.asmx");
WebRequest webRequest = WebRequest.Create(uri);
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Method = "POST";
using (Stream requestStream = webRequest.GetRequestStream())
{
byte[] paramBytes = Encoding.UTF8.GetBytes(sb.ToString());
requestStream.Write(paramBytes, 0, paramBytes.Length);
}
//响应
WebResponse webResponse = webRequest.GetResponse();
using (StreamReader myStreamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
{
Console.WriteLine(myStreamReader.ReadToEnd());
Console.WriteLine("Success...");
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
return rsp;
}
}
}
推荐阅读
-
NetCore+Redis仿微博系统(1)-注册/登录
-
Netcore webservice
-
求高人指点.net开发的webservice调用外部php写的webservice
-
.Net Core 项目发布到Linux - CentOS 7(二)用Supervisor守护netcore进程
-
php自带soap,读取webservice的xml内容中文变乱码解决办法
-
webservice - php soapserver可以设置超时时间吗
-
asp.net webservice修改类名
-
Axis2开发创建WebService
-
Axis2开发创建WebService
-
PHP调用C#Webservice如果判断是否有数据呢?