Comments (12)
We have created an issue in Pivotal Tracker to manage this:
https://www.pivotaltracker.com/story/show/155184786
The labels on this github issue will be updated when the story is started.
from discovery.
@chiragd03 To confirm I understand the problem, you're using one of the Steeltoe sample applications (Discovery/Fortune Teller) and you are trying to change it to use HTTP POST instead of HTTP Get?
If that's the case, make sure you change both the UI project and the Service project to use POST as you'll likely get a 404 if they don't use the same method
from discovery.
@TimHess thanks for an early reply, i tried to use the same sample code and created two WebAPI's, the FortuneService API code as
[HttpGet]
public string Get()
{
return "Fortune Service";
}
and the FortuneUIAPI code as
HttpClient c = new HttpClient(_handler, false);
var result = await c.GetStringAsync(@"https://FORTUNESERVICE/api/values");
return "Response form Fortune service : " + result.ToString();
This code is working fine
but when i change FortuneService code to
[HttpPost]
public string Post()
{
return "Fortune Service";
}
and the new FortuneUICode as
HttpClient c = new HttpClient(_handler, false);
var result = await client.PostAsync(@"https://FORTUNESERVICE/api/values",null);
var output = await result.Content.ReadAsStringAsync();
return "Response form Fortune service : " + output .ToString();
In this case output is null, when run on PCF, but on local i am getting response.
Please help
from discovery.
@chiragd03 I just altered a current copy of the Discovery/AspNetCore sample to use POST instead of GET and it works fine for me so I don't think there are any issues with the sample or the library.
You might want add some Console.WriteLine() statements, or if you're deploying to linux you can try debugging https://discuss.pivotal.io/hc/en-us/articles/115013948068-How-to-debug-NET-core-applications-on-Pivotal-Cloud-Foundry
from discovery.
@TimHess , i debugged the code and found this
for the line
var result = await client.PostAsync(@"https://FORTUNESERVICE/api/values",null);
i get result.IsSuccessStatusCode = false
result.ReasonPhrase = NotFound
result.StatusCode = 404
Can you please guide me where i went wrong
FortuneService API
[HttpPost]
public string Post()
{
Console.WriteLine($"::::LOGS:::: FortuneServiceCalled");
return "From Fortune service";
}
Fortune UI API
[HttpPost]
public async Task<string> Post()
{
Uri uri = new Uri(@"https://FORTUNESERVICE/api/values");
var client = new HttpClient(_handler, false);
var result = await client.PostAsync(uri, null);
var output = await result.Content.ReadAsStringAsync();
return "output : " + output;
}
Current Output : output:
Expected Output : output: From Fortune service
But if this was Get with same URI , instead of Post i get the result
Also if i use the full url (https://fortuneService.xx.xx.xx.xx.xx.xx/api/values) instead , then i am able to get the response
UPDATE :
If i add one HTTPGet function also to the FortuneService API
Added one more method to Fortune Service API
[HttpGet]
public string Get() {
return "From Fortune service GET";
}
and now if i run
Calling from Fortune UI API
var postResponse= await client.PostAsync(@"https://FORTUNESERVICE/api/values", null);
var postOutput= await postResponse.Content.ReadAsStringAsync();
and
var getOutput = await client.GetStringAsync(@"https://FORTUNESERVICE/api/values");
then both postOutput and getOutput returns "From Fortune service GET"
that is every call when made to the fortune service using the short URI , is picked up by GET method of the service
Everything works as expected when i use full uri (https://fortuneService.cfapps.pcf1.xx.xx.xx.xx/api/values)) instead of the https://FORTUNESERVICE/api/values which is the address when using service discovery
from discovery.
@chiragd03 Can you share a more complete sample? Either the entire project or the code of both controllers please.
Also which package versions are you using for ASP.NET and Steeltoe?
from discovery.
sure @TimHess ,
Fortune Service API
csproj file dependencies
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
<PackageReference Include="Pivotal.Discovery.ClientCore" Version="2.0.0-rc1" />
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="2.0.0-rc1" />
</ItemGroup>
Controller Code
[Route("api/[controller]")]
public class ValuesController : Controller
{
[HttpPost]
public string Post()
{
Console.WriteLine($"::::LOGS:::: FortuneServiceCalled");
return "From Fortune service";
}
[HttpGet]
public string Get() {
return "From Fortune service GET";
}
}
Also added code in appsettings.json ,Startup.cs and Program.cs as per sample
Once pushed to pcf , i am able to bind it to the service discovery server and getting the logs as per README of the sample
Fortune UI API
csproj file dependencies
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Pivotal.Discovery.ClientCore" Version="2.0.0-rc1" />
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="2.0.0-rc1" />
</ItemGroup>
Controller Code
[Route("api/[controller]")]
public class ValuesController : Controller
{
DiscoveryHttpClientHandler _handler;
public ValuesController(IDiscoveryClient client)
{
_handler = new DiscoveryHttpClientHandler(client);
}
[HttpPost]
public async Task<string> Post()
{
Uri uri = new Uri(@"https://FORTUNESERVICE/api/values");
var client = new HttpClient(_handler, false);
var getOutput = await client.GetStringAsync(uri);
var postResponse= await client.PostAsync(uri, null);
var postOutput= await postResponse.Content.ReadAsStringAsync();
return "output : " + postOutput;
}
}
Similarly added code in appsettings.json ,Startup.cs and Program.cs as per sample
Once pushed to pcf i am getting the logs as per README for the sample
ISSUE
- If i use the full uri in the Fortune UI API code (https://fortuneService.cfapps.pcf1.xx.xx.xx.xx/api/values), then i am getting desired output for both getOutput and postOutput respectively.
- If i am using the short uri ( https://FORTUNESERVICE/api/values) then both getOutput and postOutput calls the HTTPGet method of the FortuneService and the result in both cases is same i.e "From Fortune service GET".
- If i remove the HTTPGet method from Fortune Service then
var postResponse= await client.PostAsync(uri, null);
var postOutput= await postResponse.Content.ReadAsStringAsync();
postResponse returns status code 404
from discovery.
@chiragd03
I've tried to recreate your problem but I'm unable to .. based on what you have posted above.
Here is the repo I used to try and recreate the problem you are having : https://github.com/dtillman/DiscoveryTest
The code in the repo works for me on PCF 2.0, with SCS 1.5.
Can you give this code a try?
Dave
from discovery.
@dtillman thanks a lot for the sample,
But unfortunately i am facing the same issue,
one difference though , when pushing the code to pcf , i was facing some issue for some missing Microsoft.AspNetCore.Antiforgery.dll , so as a workaround
-
First i changed
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
to 2.0.3 - Still Microsoft.AspNetCore.Antiforgery.dll missing issue -
Then i tried to push with this buildpack- " dotnet_core_buildpack_201 "(which is what i got for development) for both 2.0.5 - Still Microsoft.AspNetCore.Antiforgery.dll missing issue.
-
finally changed csproj for both projects i.e added this line and then pushed - which worked with 2.0.5
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
so now its like
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
then i pushed both the projects to pcf
now using POSTMAN i made four request and got the following result
-
[POST] https://fortuneui-xxxx-xx.cfapps.xxx.xxx.pcf.xxxx.com/api/values
with body = "POST"
Rsponse = From Get
-
[GET] https://fortuneui-xxxx-xx.cfapps.xxx.xxx.pcf.xxxx.com/api/values
Rsponse = From Get
-
[POST] https://fortuneservice-xxxx-xxxx.cfapps.xxxx.xxx.pcf.xxxx.com/api/values
with body = "POST"
Rsponse = POST
-
[GET] https://fortuneservice-xxxx-xxxx.cfapps.xxxx.xxx.pcf.xxxx.com/api/values
Rsponse = From Get
As you can see if i am calling the service directly , i am getting post and get outputs, but when calling via fortuneui (i.e. using this uri - https://FORTUNESERVICE/api/values) , then both hit GET method only
ALSO
I checked and my pcf version is 1.12 ans SCS version is 1.5.1 . Is this what is causing this behaviour?
from discovery.
@chiragd03,
Not sure why you had to make changes to the projects .. probably some quirk with build pack?
In my testing I'm using command line and publishing SCD:
- dotnet publish -f netcoreapp2.0 -r ubuntu.14.04-x64
- cf push -f manifest.yml -p bin\Debug\netcoreapp2.0\ubuntu.14.04-x64\publish
Can you try the following changes:
-
In WebApplication1 ... in appsettings.json, remove comment for securePortEnabled (i.e.,"securePortEnabled": true,) ... this will cause the registration to enable securePort, and then when the Steeltoe HttpClientHandler does the lookup it will return a URI with the https scheme. I'm guessing you might have http disabled in the GoRouter/HaProxy and that is what's causing this behavior.
-
In WebApplication2 ... when you new the Handler add the logger to handler, _handler = new DiscoveryHttpClientHandler(client, logger);
-
Capture the log output, .... we should see Debug logs for Steeltoe components ...
Dave
FYI ... I also verified app using POSTMAN ... sending RAW content, text/plain to fortuneui app...
from discovery.
@dtillman , thanks a ton,
the "securePortEnabled": true thing did the trick ,
Was stuck with this for the past few days,
Thanks a lot again 👍
from discovery.
Glad to help.
Dave
from discovery.
Related Issues (20)
- Service Registry URL not resolved in PCF Marketplace Service HOT 3
- What is the difference Pivotal.Discovery.ClientCore and Steeltoe.Discovery.ClientCore? HOT 3
- Eureka Cluster config is not working in the Steeltoe Discovery HOT 2
- Is it possible to override the steeltoe configuration(without appsetting.json)? HOT 2
- Error message in Eureka server dashboard HOT 3
- Does eureka:client:serviceUrl support multiple eureka servers in the config? HOT 3
- Proxy settings are unused HOT 5
- Suport simpleinjector IOC HOT 7
- how to register to multiple eureka server HOT 3
- Cannot evict service from eureka. HOT 4
- How to bind multiple Eureka addresses HOT 5
- Can we set the instanceId to the current IP address and port. HOT 4
- Registering with Eureka discovery server working, but renew failing. HOT 10
- Failing to fetch registry HOT 10
- How to generate random instance id? HOT 4
- AddDiscoveryClient Should also add DiscoveryHttpMessageHandler HOT 1
- Implement Spring Cloud Consul using PR #50 HOT 2
- Refactor the Discovery Health check from PR #44 HOT 2
- DoGetApplicationsAsync Failed HOT 2
- Host Name and IP Address not computing on Mac and Docker HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discovery.