如何从现有WCF应用程序调用WebAPi ASP.NetCore [英] How do I call a WebAPi ASP.NetCore from a existing WCF application

查看:52
本文介绍了如何从现有WCF应用程序调用WebAPi ASP.NetCore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个WebAPI(可能会更改),这将由多个WCF应用程序使用.挑战在于我无法更改我有权访问的WCF应用程序代码.

I am needing to create a WebAPI ( may change)  middle wear application that will be consumed by several WCF applications. the challenge is that I can not change the WCF application code I do have access to it.

我在控制器中添加了Restful方法,并且看到该调用以POST的形式出现.问题是我看不到请求中的任何数据.我已经使用[fromBody]装饰了参数.仍然没有成功

I've added Restful methods in the controller and I see the call coming in as a POST. the problem is that I cannot see any of the data from the request.  I've decorated the  parameters using [fromBody]. still no success

WCF请求:

 公共System.Threading.Tasks.Task< MySvc.aResponse> fAsync(字符串AMethod,字符串ANumber,字符串函数,字符串环境,字符串AString,字符串AInd)
        {
            MySvc.fEgcaRequest inValue = new MySvc.fequest();
            inValue.Body = new MySvc.fRequestData();
            inValue.Body.ActivationMethod = AMethod;
            inValue.Body.aNumber = ANumber;
            inValue.Body.Function =函数;
            inValue.Body.Environment =环境;
            inValue.Body.TStr = AString;
            inValue.Body.AcctDeactPrevInd = AInd;
            return(((MySvc.caPortType)(this)).MySvc(inValue);

 public System.Threading.Tasks.Task<MySvc.aResponse> fAsync(string AMethod, string ANumber, string Function, string Environment, string AString, string AInd)
        {
            MySvc.fEgcaRequest inValue = new MySvc.fequest();
            inValue.Body = new MySvc.fRequestData();
            inValue.Body.ActivationMethod = AMethod;
            inValue.Body.aNumber = ANumber;
            inValue.Body.Function = Function;
            inValue.Body.Environment = Environment;
            inValue.Body.TStr = AString;
            inValue.Body.AcctDeactPrevInd = AInd;
            return ((MySvc.caPortType)(this)).MySvc(inValue);

WebAPI发布:

[HttpPost]

[HttpPost]

公共Myresponse Put([FromBody] MyResponse  data)

public Myresponse Put([FromBody] MyResponse  data)

{

var tempData = data;

var tempData = data;

...

}

*** Put方法中的data参数不包含数据.

*** the data parameter in the Put method does not contain data.

推荐答案

嗨劳伦斯,

>>挑战在于我无法更改我有权访问的WCF应用程序代码.

您是说无法在WCF应用程序中创建新方法或修改现有方法?如果是这样,我认为您无法从WCF应用程序调用WebAPI.

如果您可以在WCF应用程序中更改代码,建议您尝试 HttpClient ,以从WCF向WebAPI发出请求.

If you could change code in WCF application, I suggest you try HttpClient to make request to WebAPI from WCF.

最好的问候

爱德华


这篇关于如何从现有WCF应用程序调用WebAPi ASP.NetCore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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