I have two application, both deployed in same cluster.
Now from web, there is an ajax request to get data from api, but it always return 502 Connection refused.
here is my jquery code (web).
$.get("http://10.43.244.118/api/users", function (data) {
console.log(data);
$('#table').bootstrapTable({
data: data
});
});
Note: when I change the service type to LoadBalancer from ClusterIP then it works fine.
ClusterIP services (usually) only work within the cluster. You can technically make your CNI address space available externally, but that is rare and you probably shouldn't count on it. The correct way to expose something outside the cluster is either a NodePort service or a LoadBalancer (which is a NodePort plus a cloud load balancer).
1\Ajax is a front-end call to api.
2\The front-end call is to directly communicate with the user(Browser) and the called end and the api service.
3\ ClusterIP is internal to the cluster,User(Browser) cannot communicate with it.
4\ NodePort and LoadBalancer can expose the internal network, of course, it can be accessed normally.
Related
I am new to web services.
I have built a web service in C# that consumes a third party service and then returns the XML response from that call in a web method.
When I test this in IIS on the local web server it works perfectly.
However when I try to call or invoke the service via the URL I use on the test page I can't return a response.
If I use a GET I simply get the test page loading and the message I can't use this test page outside of the local server.
In short, I simply want to know how to call the web method externally and mimic the INVOKE button being pressed so I get the response passed back.
This is probably really simple but I can't get my head around it.
In addition if I use Postman to try and call the URL:
WebService.asmx?op=GetSalesOrders
I get the error message detailed below which is a step forward but I am still unsure about how to package up a call to this service
You call the service by making a POST request with a properly formated SOAP message to this URL:
<path>/WebService.asmx
You get the WSDL of the web service by making a GET request to this URL:
<path>/WebService.asmx?wsdl
You can use that WSDL to build a client or test the service with something like SoapUI. See this and this for more details.
That invocation page or URLs with parameters like this:
<path>/WebService.asmx?op=GetSalesOrders
are just provided for convenience to allow you to poke at the service and make sure the service is running. They should not be used in "real" calls.
I have a .Net Core 3.1 server published to Azure websites. As part of this server, it has an API endpoint which I need to call with another application. The controller for this endpoint does a couple of things, but crucially it calls another, external API endpoint using HttpClient.
I don't think the issue is with any code, but for reference, this is what the HTTP request from server to external API looks like:
try
{
string endpoint = baseAdress + cpe;
string responseBody = await client.GetStringAsync(endpoint);
// ... It fails at the line above, the rest of this just parses the response body
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
// "Response status code does not indicate success: 502 (Bad Gateway)."
}
When I run this server locally and set my client-side application to call the server-side endpoint at localhost, everything runs smoothly. The controller runs, calls this external API, gets the results, and then does some parsing and returns a response to my client-side application.
When I publish the server up to Azure and have the client-side to point its API call there, there is no issue. However, the server's attempt to call the external API results in a 502 error.
Does Azure block servers from calling external endpoints? Or am I missing some settings which I need to change? I've never used Azure websites before, so this is all very new territory for me, apologies if I've made some silly assumptions/mistakes. The only other people I have seen post about these problems are having issues with timeouts, however when I run this locally is generally completes within around 30s, so I don't believe that is the problem here.
Since you're calling an API on a different domain, make sure CORS is enabled on your web app.
az resource update --name samsapp--resource-group myResourceGroup --namespace Microsoft.Web --resource-type config --parent sites/<app_name> --set properties.cors.allowedOrigins="['http://api.com']" --api-version 2015-06-01
In Visual Studio 2015 I have 2 projects in my solution: ASP.NET MVC app and an ASP.NET Web API app. The MVC app uses a different port in IIS express than the Web API app.
In the debugger I see that I end up in the ChangeName method Web API controller, but the parameter never gets set and then in the console I see errors. The errors have to do with cross domain problems.
Is it this complicated to make a jQuery AJAX request to a different domain? When I use fiddler everything works fine.
The domain for the app that the below code is in is: localhost:50675 and I am trying to make a request to another project in the same solution that is localhost:27081
Here is my AJAX request:
$("#btnChangeName").click(function() {
var name = $("#Name").val();
var url = 'http://localhost:27081/api/products/changename';
$.ajax({
url: url,
type: 'POST',
dataType: 'text',
data: JSON.stringify({name: name}),
success: successFuncApi,
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
});
Here is one of the errors I am seeing in the console:
XMLHttpRequest cannot load http://localhost:27081/api/products/changename.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:50675' is therefore not allowed access.
The response had HTTP status code 500.
I am not sure if the error is due to my controller erroring since the param is null or if it is the root of my problem.
The Error occurs because you send a request from origin (source) to another one.
all you need to do is to enable cross origin in your backend (or your ASP.NET Web API) to be added in the header.
this link will give you more information, and guide you to enable cross-origin requests.
This error might go away, when you move your apps to production (depending on the setup of webservers). As for now, I would try something, as explained here Enabling Cross-Origin Requests in ASP.NET. If this doesn't fit your situation, there are other ways to enable the same thing.
You could also deploy your apps on IIS. Create app for client, then add new app to that app for webapi.
I'm working on an Azure service for a Windows Phone app. I need the Azure Service to access the users' OneDrive. Following this article, my scenario should be:
The user sign in to Windows Live on the WP app.
The Live web service sends the authorization code to a redirect URI that I defined, with the code appended as a query parameter named code, as:
http://www.example.com/callback.php?code=2bd12503-7e88-bfe7-c5c7-82274a740ff
I get the authorization code and access the users' data
After investigating a lot in Service, I still can't find a way to capture the query parameter in my web service. As I am new to this area, I don't know where to focus on. I'll be really appreciated if you can give my an advise or answer my following questions:
Can I access the service just using the url with parameter in a browser? How can I see if the service is working properly?
An article mentioned using WCF [Web Get] attribute to get Query Parameters, but I still don't know how to implement both the IService1.cs and Service1.cs file, could you give me a sample about how to access the value of Query Parameter?
Thanks!
I'm not sure if i understand your problem properly but if you want your RESTfull WCF service to be the callback receiver for the request code, your Service must be hosted with a WebHttpBinding and a ServiceContract similar to this one.
[ServiceContract]
public interface IService
{
[WebGet(UriTemplate = "callback?code={requestCode}")]
void OAuthCallback(string requestCode);
}
So if the base address of your Service is "http://service.mydomain.com/MyService.svc" the OAuthCallback Method will be called when a http GET request to "http://service.mydomain.com/MyService.svc/callback?code=RequestCode" is made.
I am working on an ASP.NET MVC3 project, i am using Ajax jquery to communicate with my controllers. i use asp.net caching to store the results before updating the database (SQL Azure).
function SaveCustomersList() {
$.ajax({
type: "POST",
url: '/Customers/SaveCustomersList/',
data: "",
cache: false,
dataType: "text",
success: function (data) {
return true;
}
});
}
The application work fine but not for all users !!
When some users try to update the database the content passed to my DAL objects is null.
this is just happening with the users working on a network.
i have no explanation for that.
thanks for your help.
Here is a list of questions you need to answer to get proper help:
How many instances of your application is running?
Where this application is running and local network or hosted outside?
When you say "users working on a network", what do u mean? Does it mean this application is accessible to users within your network or outside network?
If this application is running in your network, and the communication between Ajax calls and controller is passing through proxy, only then Proxy could be a factor.
As you are using InProc cache the problem It is critical to know if you have multiple instances of this application. You need to understand that the communication between your Ajax and controller is instance specific and if you have local cache to handle it that will work with only one instance. However if you have multiple instance of the same application and using local cache will not work properly because there is no guarantee that connection X served by instance #1 will always be server by instance #1.
If you decided to run application on multiple instance, using distribured cache (i.e. Outside your instance) is the only choice you have comparative to internal (i.e. Insides your instance ASP.NET inproc) Cache.
[Added]
Here is a .net sample application to use Windows Azure Cache:
https://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/
If you wish to use MemCache you can use #smarx solution as described below:
http://blog.smarx.com/posts/memcached-in-windows-azure
What you need to do is set up a distributed cache that allows you to cache data between multiple instances. You can use Azure Caching for this (but it is expensive!).
Setting the caching up is fairly easy, just follow this guide: https://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/