首先随便创建一个简单的webservice测试
using System;然后在netcore中引用service,项目上面右键,添加,服务引用,如下图
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從指令碼呼叫此 Web 服務,請取消註解下一行。
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () {
//如果使用設計的元件,請取消註解下行程式碼
//InitializeComponent();
}
[WebMethod]
public ReturnObject ReturnTest() {
ReturnObject ro= new ReturnObject();
ro.ReturnCode = "0000";
ro.ReturnMessage = "ok";
ro.ReturnResult = true;
return ro;
}
}
[HttpPost]结果如下 :
public IActionResult StockOut()
{
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress(“http://localhost:55378/WS_Test/Service.asmx”);
ServiceSoapClient soapClient = new ServiceSoapClient(binding, address);
var helloWorldRespone = soapClient.ReturnTestAsync();
ReturnObject ro = helloWorldRespone.Result.Body.ReturnTestResult;
return Ok(new { ro });
}
- 本文标题: NetCoreAPI调用WebService
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.