I'm using TFS 2015 Webhook to be notified when a checkin occurs. I've created an API using .NET 4.6 so I can receive the notifications. It works perfectly when I use Visual Studio 2015 to load the API, but once I publish it to IIS 7, TFS starts to show Status Code: 500, even if the code is executed without any exception.
Here is the method from the Web Api. I'm writing an output to log, to make sure it is executed. It writes "returning success" every time.
public HttpResponseMessage Post([FromBody]Models.Content value)
{
try
{
IndexUpdater iUpdater = new IndexUpdater();
iUpdater.UpdateIndex(value.resource.changesetId);
using (StreamWriter w = File.AppendText("C:\\publish\\TFSListenerAPI\\log.txt"))
{
w.WriteLine("returning success");
}
return Request.CreateResponse(HttpStatusCode.OK);
}
catch(Exception ex)
{
using (StreamWriter w = File.AppendText("C:\\publish\\TFSListenerAPI\\log.txt"))
{
w.WriteLine("erro");
w.WriteLine(ex.Message);
}
}
}
Here is the returned message
Here is the return when I execute the API using Visual Studio, same code.
Edit: Just found out that the error 500 happens only when the below method is executed. The weird part is the fact that the code works, and the content is
returned with success.
private string GetFileContent(string tfsPath)
{
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://tfs2015.com.br:8080/tfs/cd-jv"), new System.Net.NetworkCredential("user", "password"));
server.Authenticate();
VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
Microsoft.TeamFoundation.VersionControl.Client.Item item = version.GetItem(tfsPath);
string tempFileName = System.IO.Path.GetTempFileName();
item.DownloadFile(tempFileName);
var content = File.ReadAllText(tempFileName, Encoding.GetEncoding("ISO-8859-1"));
return content;
}
So, as I edit the post after posting it, the problem is in this line:
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://tfs2015.com.br:8080/tfs/cd-jv"), new System.Net.NetworkCredential("user", "password"));
For some reason, if this request is made before the API returns OK to the Webhook, the Webhook shows the error 500. So the way I found to make it work was by making sure this line is executed only after tue API returns OK. It can be done by using Async/Await and Thread.Sleep().
According to the error message Status Code: 500 it should be internal server error, something strange and unusual happened that was likely not your fault at all.
Try to check the event viewer, if there are any other logs with HResult codes when you encounter 500 error on an Internet Information Services (IIS) 7.0. Then refer to below article for further trouble shooting:
HTTP Error 500.0 – Internal Server Error" error when you you open an IIS 7.0 Webpage
Also check if this thread helps for you : How do I receive a custom webhook in an IIS hosted website?
Related
I am trying to make make a RingOut call with RingCentral using their RingCentral SDK. I am basically following their tutorial found here:
https://developers.ringcentral.com/guide/voice/quick-start/c-sharp
Other than the fact that I'm trying to do this in an MVC web app and not in a console app my code basically looks identical to theirs:
public async Task<JsonResult> Call(string number)
{
var rc = new RestClient(RingCentralCredentials.ClientId, RingCentralCredentials.ClientSecret, false);
var tokenInfo = await rc.Authorize(RingCentralCredentials.Username, RingCentralCredentials.Extension, RingCentralCredentials.Password);
// The above line throws the exception.
var parameters = new MakeRingOutRequest();
parameters.from = new MakeRingOutCallerInfoRequestFrom { phoneNumber = RingCentralCredentials.Username };
parameters.to = new MakeRingOutCallerInfoRequestTo { phoneNumber = number };
parameters.playPrompt = false;
var resp = await rc.Restapi().Account().Extension().RingOut().Post(parameters);
return Json(resp.status, JsonRequestBehavior.AllowGet);
}
yet for some reason when I run this code I get the following error when the execution gets to the Authorization line:
Cannot access a disposed object.
Object name: 'System.Net.Http.FormUrlEncodedContent'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.FormUrlEncodedContent'.
Does anyone have any advice with regards to this? The SDK version I'm using is 1.2.1:
https://www.nuget.org/packages/RingCentral.Net/1.2.1
The original app in the tutorial is a console app. Can you also reproduce the issue with a console app? Or is this a web app only issue?
I saw you opened a RingCentral support case. I will reply you in that support case. Once we found the root case I will post update here.
Update: I've tried the sample code provided by Marko and I think I've found the root cause. The RingCentral app being used doesn't allow password flow while we tried to authorize by password. More information about this issue: https://forums.developers.ringcentral.com/questions/452/http-400-unauthorized-for-this-grant-type.html
I'm trying to work through the hello world example on the Neo4j .Net driver page but every time I try to run the example, it spins for a while and then throws an exception:
Neo4j.Driver.V1.ServiceUnavailableException: 'Failed after retried for
5 times in 30000 ms. Make sure that your database is online and retry
again
I've confirmed my database is running as I can see it through the neo4j browser running at localhost:7474. I'm trying to create the connection as follows
// Invocation in Main method
using (var greeter = new HelloWorldExample("bolt://localhost:7474", "neo4j", "neo4j"))
{
greeter.PrintGreeting("Hello, World");
}
...
// Constructor for HelloWorldExample, and where it's getting hung
public HelloWorldExample(string uri, string user, string password)
{
_driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
}
I've tried several different variants of the URI (such as using port 7687, like the example says, even though that's not where my instance is running) as well as trying to use http instead of bolt as the protocol (which threw a completely different error, saying that's not allowed) to no avail. Anyone know what I might be missing?
You are using the wrong port, that is the UI port. You need to connect to port 7687 (if you are using the defaults, which I assume you are)
using (var greeter = new HelloWorldExample("bolt://localhost:7687", "neo4j", "neo4j"))
{
greeter.PrintGreeting("Hello, World");
}
I am writing an bot in C# with the Microsoft Bot Framework which is hosted as Azure web app and calls either some Azure API or a Google Cloud API.
Locally everything works fine but when deployed to Azure the Call to the Google Cloud API never returns and my the Microsoft Bot Frameworks gives me an timeout error message.
I searched through the Azure portal in order to find some more detailed information why this outgoing call might not return correctly but so far I found nothing useful. I can't see any error on the diagnostics sites and remote debugging just never return from the API calls.
Does anybody know if I can enable some more debug/error information for this problem?
Edit after comments:
#Mark C.: I am able to call and get a result form the Google Service (text sentiment) when I run the app locally, so the Google Cloud API should be fine.
#Hackerman: The mapping is know to me. I try to compare some Services between Azure and Google, in this case the text sentiment API. I enabled stream logging, but there are no errors/warnings printed out.
#Bruce MSFT: The method is like this. Both azure and google paths work locally. Only the Azure path works when deployed to Azure web apps. When I remote debug the Azure Web App I can step to "client.AnalyzeSentimentAsync" and when I press next the next line is never reached. Instead after 10 (?) minutes I get an exception from mscorlib: "{"Status(StatusCode=DeadlineExceeded, Detail=\"Deadline Exceeded\")"}"
public async Task<int> DetectSentiment(string text, bool useAzure = false)
{
if (useAzure)
{
var request = new SentimentRequest();
request.Documents.Add(new AzureDocument
{
Id = Guid.NewGuid().ToString(),
Text = text
});
var client = new SentimentClient(_key);
var response = await client.GetSentimentAsync(request);
return Convert.ToInt32(response.Documents[0].Score * 100);
}
else
{
try
{
var client = LanguageServiceClient.Create();
var response = await client.AnalyzeSentimentAsync(new GoogleDocument
{
Content = text,
Type = GoogleDocument.Types.Type.PlainText
});
return Convert.ToInt32((response.DocumentSentiment.Score + 1) * 50);
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
}
When I am trying to post a data to an API using HttpClient in Windows Phone 8.1, I am always getting Exception from HRESULT: 0x80072F0D exception. In fiddler, it works fine.
try
{
var requestbody="json data"
HttpClient httpClient = new HttpClient();
HttpRequestMessage msg = new HttpRequestMessage(new HttpMethod("POST"), new Uri(addressUri));
msg.Content = new HttpStringContent(requestbody);
msg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
HttpResponseMessage response = await httpClient.SendRequestAsync(msg).AsTask();
}
catch (Exception ex)
{
getting **Exception from HRESULT: 0x80072F0D**
}
Please tell me what went wrong?
---FYI----
For getting additional information about the HRESULT code : Follow this WebErrorStatus enumeration
var exceptionDetail = WebError.GetStatus(ex.GetBaseException().HResult);
if (exceptionDetail == WebErrorStatus.HostNameNotResolved)
{
//
}
This looks like a certificate related problem. Maybe you are using SSL. While lots of programs gracefully override missing certificates if not explicitly necessary (e.g.: browsers) the HttpClient is pretty sensitive against that.
You should try to download the certificate for the connection you're using and store the cert file in your assets folder. When your app starts, push it into the certificate store. This is a snippet I am using in one of my apps. Maybe this makes your exception go away.
Read more here: http://blogs.msdn.com/b/wsdevsol/archive/2014/06/05/including-self-signed-certificates-with-your-windows-runtime-based-windows-phone-8-1-apps.aspx
// Add our custom certificate
try
{
// Read the contents of the Certificate file
System.Uri certificateFile = new System.Uri("ms-appx:///Assets/ca.cer");
Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(certificateFile);
Windows.Storage.Streams.IBuffer certBlob = await Windows.Storage.FileIO.ReadBufferAsync(file);
// Create an instance of the Certificate class using the retrieved certificate blob contents
Windows.Security.Cryptography.Certificates.Certificate rootCert = new Windows.Security.Cryptography.Certificates.Certificate(certBlob);
// Get access to the TrustedRootCertificationAuthorities for your own app (not the system one)
Windows.Security.Cryptography.Certificates.CertificateStore trustedStore = Windows.Security.Cryptography.Certificates.CertificateStores.TrustedRootCertificationAuthorities;
// Add the certificate to the TrustedRootCertificationAuthorities store for your app
trustedStore.Add(rootCert);
}
catch (Exception oEx)
{
// Catch that exception. We don't really have a choice here..
var msg = oEx.Message;
}
You might be able to bypass the error with this code:
var baseFilter = new HttpBaseProtocolFilter();
baseFilter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidCertificateAuthorityPolicy);
var httpClient = new HttpClient(baseFilter);
This merely silences the error rather than solving the problem, though. I'm not too knowledgeable with SSL errors, and this may not be a safe option, and may not pass app certification. According to the docs:
SSL server certificate errors should only be ignored in advanced scenarios. Disregarding server certificate errors classified as either Ignorable or Fatal may result in the loss of privacy or integrity of the content passed over the SSL session.
Received the same Error as originator. I do not use a proxy.
This worked for me. netsh winhttp reset proxy
Next Fax transmitted without error.
Experienced the 0x80072efd problem. Has cost me hours if not days to solve. The solution that gave instant resolution is the following command from a admin command prompt:
netsh winhttp reset proxy
I am trying to render a report using the ReportExecution2005 web service. I have no problems rendering a report locally, but when I try to call it on Azure, it always fails with the message that the item can't be found.
The report is called "Invoice.rdl". Here's how I'm calling it (snippet):
ReportExecutionService rs = new ReportExecutionService()
{
CookieContainer = new CookieContainer(),
ExecutionHeaderValue = execHeader,
Url = string.Format("https://{0}:443/ReportServer/ReportExecution2005.amsx", "myUrl")
}
rs.LogonUser("myUsername", "myPassword", "myUrl");
rs.LoadReport("/Reports/Invoice", _historyId); // here the exception is thrown
I've tried it with different paths, e.g. /Invoice, /SSRSReport/Invoice, /ReportServer/Invoice etc., none seem to work.
Any ideas?
OK, turned out to be a stupid problem.
When uploading the report from the old Windows Azure management portal, it would leave the ".rdl" file extension in the name.
Removing it fixed the problem.