简体   繁体   English

参数值不一致-Azure API App Client调用本地IIS托管API

[英]Unconsistent values of parameter - Azure API App Client calls locally IIS Hosted API

I have been sitting all day and can not figure this out. 我整天都坐在那里,无法解决这个问题。 I have made seaches on stackoverflow and the web but have found no answers. 我已经在stackoverflow和网络上进行了搜索,但是没有找到答案。

Setup 设定

This is not the optimal setup but it is what I have to deal with because of legacy code. 这不是最佳设置,但由于遗留代码,我必须处理。

I have a FileController (API controller) class hosted on the client web that is used to upload files. 我在客户端网络上托管了一个FileController(API控制器)类,该类用于上传文件。 A MVC Controller is making a jquery.ajax call throug angular to the FileController.UploadFiles(). MVC控制器正在通过FileController.UploadFiles()的角度进行jquery.ajax调用。 The FileController.UploadFiles() get some data out from the database and then send a request to the storageAPI which store the file in a blob in a certain way depending on the settings parameter inside the CustomResponse object. FileController.UploadFiles()从数据库中获取一些数据,然后将请求发送到storageAPI,后者根据CustomResponse对象内的设置参数以某种方式将文件存储在Blob中。

The problem is that the parameter CustomResponse is null sometimes when it gets to the controller and sometimes I actually has a value. 问题是参数CustomResponse有时在到达控制器时为空,有时我实际上有一个值。 It's seems to be totally random. 这似乎是完全随机的。

I have tested it manually by clicking a upload button on my Client GUI that calls the FileController with Ajax which in turn calls the API. 我已经通过单击客户端GUI上的上载按钮(使用Ajax调用FileController并依次调用API)手动测试了它。 Both the client web and the storage api is hosted locally and hosted on a local IIS. 客户端Web和存储api都在本地托管,并在本地IIS上托管。 Can it be a collision? 会发生碰撞吗?

It's not null when I use the Swagger UI to do posts. 当我使用Swagger UI进行发布时,它不为null。 Then it gets the content parameter everytime. 然后,它每次都会获取content参数。

The request always reach the Storage API when i debug. 当我调试时,请求始终到达Storage API。 So the "wiring" between them is fine. 因此,它们之间的“接线”很好。

I have tried to do both async and not async calls and have change the method in the API also to be sync and async no difference. 我已经尝试进行异步调用,而不是异步调用,并且更改了API中的方法以使其同步和异步也没有区别。

Code

Code

FileController (CLIENT) FileController(客户端)

byte[] fileBytes = null;
using(var memoryStream = new MemoryStream())
{
    file.InputStream.CopyTo(memoryStream);
    fileBytes = memoryStream.ToArray();
}
var fileBytesString = System.Text.Encoding.UTF8.GetString(fileBytes);
var settingsString = "renditions:large,thumbail;assettype:testdataimage;testdataid:" + testData.Id.ToString() + ";filename:" + fileName;

var client = new StorageAPI();
client.BaseUri = new Uri("http://storageapi.mycompany.local/");

CustomResponse response = null;

response = client.Blob.Post(new CustomRequest()
{
     FileBytesString = fileBytesString,
     Settings = settingsString
});

client.Dispose();

StorageAPI Model CustomRequest StorageAPI模型CustomRequest

public class CustomRequest
{
    public string FileBytesString { get; set; }
    public string Settings { get; set; }
}

StorageAPI Controller StorageAPI控制器

[HttpPost]
[ResponseType(typeof(CustomResponse))]
[Route("api/Blob/")]
public HttpResponseMessage Post(CustomRequest content)
{
    if (content == null)
    {
        return new HttpResponseMessage(HttpStatusCode.InternalServerError);
    }

    //Parse data and upload file to blob.

    return new HttpResponseMessage(HttpStatusCode.OK);
}

I'm looking forward to get some feedback to what I'm doing wrong here. 我期待收到一些关于我在这里做错事情的反馈。

Regards 问候

First of all thanks for your helpful comments that leed me in the right direction. 首先,感谢您的宝贵意见使我朝正确的方向发展。

I configured both the API and the Web to go through the Fiddler Proxy and looked at the request and nothing that matter was different. 我将API和Web都配置为通过Fiddler代理,并查看了请求,没有什么不同。

Then I again started to look at the content I'm sending (pictures) and it turns out it is a size issue, the larger picture did not go through but the smaller did not. 然后,我再次开始查看我要发送的内容(图片),事实证明这是大小问题,较大的图片没有通过,而较小的图片没有通过。 I searched for what the default size is for a ASP.NET application and it is 4096 kB and one of my images was larger than that! 我搜索了ASP.NET应用程序的默认大小,它的大小是4096 kB,我的一张图片比那大!

This line in the web.config in the system.web section solved the problem. system.web部分中web.config中的这一行解决了该问题。

<httpRuntime targetFramework="4.5" maxRequestLength="8192"/>    

This has been a good learning for me and I hope it might help someone else that is new to this sending large files over the wire thing! 这对我来说是一个很好的学习,我希望它可以帮助通过有线发送大文件的新手!

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 API 在本地返回 EF Core 记录,但在 Azure 中托管时不返回 - API Returns EF Core records locally, but not when hosted in Azure Azure 代理,CORs 请求时出错 IIS 托管 Z8A5DA52ED126447AD359E70C0572 - Azure Proxy, CORs error when request IIS hosted api 如何从Azure Web应用程序与IIS本地托管的WCF服务进行通信? - How to communicate from Azure web app to WCF services hosted locally in IIS? 400 Bad Request - 在本地进行nancy自托管Web API调用时无效的主机名 - 400 Bad Request - Invalid Hostname when making nancy self hosted Web API calls locally API 托管在 Azure 但数据库托管在我们的网络中 - API Hosted in Azure but Database is Hosted in our Network ASP.NET Web API服务器代码在本地运行时连接到数据库,但在Azure上托管时不连接到数据库 - ASP.NET Web API server code connects to database when run locally, but not when hosted on Azure Azure API App客户端未生成枚举 - Azure API App client is not generating enums 将客户端 IP 从 ASP.NET Web API 转发到 Azure 中托管的 .NET Core API - Forward client IP from ASP.NET Web API to .NET Core API hosted in Azure GetClientCert 未在 IIS 托管的 api 上接收 - GetClientCert is not picking up on IIS hosted api 如何在IIS中本地托管的应用程序的URL中添加自定义目录? - How to add custom directory in URL for app hosted locally on IIS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM