[英]The remote server returned an error: (404) Not Found error for API calls after server publish
We built an API service using asp.net.我们使用 asp.net 构建了一个 API 服务。 The calls work fine on the local machine with IIS Express and port 51937. But we get "The remote server returned an error: (404) Not Found" error when we try to access the API after publishing to the server.
这些调用在具有 IIS Express 和端口 51937 的本地计算机上运行良好。但是当我们在发布到服务器后尝试访问 API 时,我们收到“远程服务器返回错误:(404) 未找到”错误。
Here is the API project structure这是API项目结构
Here is how we are calling the method from console app, just to test it这是我们如何从控制台应用程序调用方法,只是为了测试它
using Mercury_Api;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace DemoConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string consumerKey = "xxx";
string consumerSecret = "xxxxx";
//var uri = new Uri("http://localhost:51937/MercuryDataConnectivity.svc/GetSidewalksXml/0/0/267");
//var uri = new Uri("http://localhost:51937/MercuryDataConnectivity.svc/GetSidewalksJson/0/0/267");
var uri = new Uri("http://testsite.com/MercuryDataConnectivity.svc/GetSidewalksXml/0/0/267");
string url, param;
var oAuth = new OAuthBase();
var nonce = oAuth.GenerateNonce();
var timeStamp = oAuth.GenerateTimeStamp();
var signature = oAuth.GenerateSignature(uri, consumerKey,
consumerSecret, string.Empty, string.Empty, "GET", timeStamp, nonce,
OAuthBase.SignatureTypes.HMACSHA1, out url, out param);
WebResponse webrespon = (WebResponse)WebRequest.Create(
string.Format("{0}?{1}&oauth_signature={2}", url, param, signature)).GetResponse();
StreamReader stream = new StreamReader(webrespon.GetResponseStream());
Console.WriteLine(stream.ReadToEnd().ToString());
//txtResult.Text = stream.ReadToEnd();
Console.ReadLine();
}
}
}
On the local machine both XML and Json methods return values, but on the server we get the not found error.在本地机器上,XML 和 Json 方法都返回值,但在服务器上,我们收到未找到错误。
The website is definitely working as the directory listing works fine, see below该网站肯定可以正常工作,因为目录列表工作正常,请参见下文
However clicking on any of the files throws the following 404 error但是单击任何文件都会引发以下 404 错误
So far I have checked the directory permissions, application pool permissions, tried.Net framework 4.0 and unmanaged code for pool, tried both integrated/classic modes for pool.到目前为止,我已经检查了目录权限、应用程序池权限、尝试过的.Net framework 4.0 和池的非托管代码,尝试过池的集成/经典模式。
Appreciate any help.感谢任何帮助。
Thanks谢谢
Finally found a solution.终于找到了解决办法。 Application pool set to Framework 4.0, integrated mode, disabled and re-enabled all WCF services, registered asp.net using the following command C:\windows\Microsoft.NET\Framework\v4.0.30319->aspnet_regiis –iru C:\windows\Microsoft.NET\Framework64\v4.0.30319->aspnet_regiis –iru
应用程序池设置为 Framework 4.0,集成模式,禁用并重新启用所有 WCF 服务,使用以下命令注册 asp.net C:\windows\Microsoft.NET\Framework\v4.0.30319->aspnet_regiis –iru C:\windows \Microsoft.NET\Framework64\v4.0.30319->aspnet_regiis –iru
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.