I am trying to test the possibility to convert all my WCF service to WebAPI but so far it's a mess. WCF is easy because you create a default project and add 1 or 2 sample method that return anything then add as a service by using the http address and it works out of the box.
On WebAPI you add connected service and type the address and it throw errors so obviously out of the box it has errors and is missing stuff to actually work.
My question is what is missing to WebAPI made with .NET6 to be able to be connected to ?
Following Microsoft example what i should do is to run the service obviously. Then use the path of the json file generated by swagger and input that in the URL of the connected services, give it a namespace and a classname and your good to go.
Step 1 : Running the service
This works i can call the basic 3 method i made for test purpose that return string, List<string> and List<List<string>> and i can execute the "tryout" button and they output everything that it needs
Step 2 : Copy the json file path provided by Swagger
I assumed that this url is good by default. I can click it and i see the definition which seems good.
Step 3 : Create and empty console app and add the connected service
When adding the connected service i pick OpenAPI as it's the only option anyway.
Then it asks for File or URL that i put my value form the service that is running. In this case this is : https://localhost:44341/swagger/v1/swagger.json. I then choose the namespace of WebTest1 and classname of WebTest2 as i dont care and click next
Step 4 : Configuration progress
This is where i have the error which is where i see that the service that can actually run cannot be connected to
Checking project for required NuGet packges... Downloading service
reference from https://localhost:44341/... ErrorFailed adding service
reference(s). Failed to download metadata file from :
https://localhost:44341/.
I finally figured out the temporary fix. I was also able to copy this project over to a colleague and the issue is the same. The problem lies into Visual Studio defaulting for some reason on the debug option of IIS Express which does properly run the service when you press F5 and your browser open normally and you can test things out. The problem is that when you project runs under IIS (actually configured like it would be the real deal) or IIS Express (the only IIS option in the debug setting) you cannot from another application connect to that service.
However if you switch the debug option to the project name and run your WebApi with that instead it also works as expected from the browser that it open but you now can actually add that service from another application without any error.
Personally i have a third option which is WSL which i "guess" is the linux sub system i can't tell as this crash when i try to start and there is no help for the UI of Visual Studio to help understand these menu options.
Now i still have a problem to attach to one running in a real IIS which is probably linked to the same reason why IIS Express debug doesn't work. So i now know that the base code works and now it's an issue of finding why the default doesn't let other application consume from IIS / IIS Express.
For reference purpose this is the debug menu in question where the IIS Express option is not working but selecting the project name like pointed out on the picture actually works.
Related
In my VS solution, there are 3 projects as below:
1) Bot2015
2) Bot2015_2 (Startup Project)
3) DB
Bot2015_2 is my Startup Project but whenever I try to test the Bot2015_2 bot application via emulator, it calls the Message Controller of the first project i.e. Bot2015 (that is the issue here). It should access the Message Controller of the start up project i.e. Bot2015_2. Even if I unload the Bot2015 and test the application, same thing is happening, it never calls the correct Message Controller i.e. of Bot2015_2.
Please help me on this!
Thank You.
Double check what port are you using to communicate with your emulator. This is what the emulator use to communicate with your controllers.
To specify a port for a Web application project that uses IIS Express
In Solution Explorer, right-click the name of the application and then select Properties.
Click the Web tab.
In the Servers section, under Use Local IIS Web server, in the Project URL box change the port number.
To the right of the Project URL box, click Create Virtual Directory, and then click OK.
In the File menu, click Save Selected Items.
To verify the change, press CTRL+F5 to run the project.
The new port number appears in the address bar of the browser.
You can check more info here: MSDN
I have client-server .net application, WCF communication with IIS.
During development I encountered a strange phenomenon:
Once in a while, when I run my application without debug and press a button - it seems like the server doesn't respond to the action.
Then I turn to check the same action on debug mode, and when I try to attach the service to process in oder to debug it - I can't find the w3wp.exe process, which is surely active !
But when I open the inetmgr (IIS Manager) and press Browse to the service site - suddenly the service is found in the Attach to process list on VS, and everything continues to work - with or without debug mode - as if nothing had happened.......
Does anyone experienced something similar, or have any assumption why is this happening?
I am concerned that similar incidents can affect the stability of my system.
Note: Perhaps the phenomenon above occurs after I update the client service reference, but I'm not pretty sure.
Thanks!
I'm not exactly if I will answer your question since it's not clear but let me put answer anyway:
I sometimes get an error in running WCF on my machine and this because I have my host running Local IIS then when I change it to IISExpress it runs without issues.
To change this, right click the project -> properties-> open web tab, locate servers and select IIS Express in dropdown. See image
To understand the difference between the two you can check: http://weblogs.asp.net/scottgu/introducing-iis-express
I have a website set up in iis 7.0 on my local win 7 machine. Within this are several webservices - they all can be accessed fine, and I can test this access by going to a browser and checking at http://localhost/test/service.svc. This works fine. I'm not trying to recreate this environment on VM with win server 2012 R2, and iis 8.5. I've set up everything identically, except then navigating to the url above returns on the 1k tb inside the actual service.src as if I opened it in notepad. If I try to add a reference to this service in VS, I get a better error and one that is related to the mime type for svc. Here's an example.
Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'file Extension' set to '.svc'.
Based on this issue, I then found a reference to needing to add something along the lines of to my config file which I do.
Now here's the interesting part. If I remove any references to the svc mime type in iis in both the server and the site, I receive a 404 not found error when trying to run a service. If I use the example above to add this with the config file, I receive a duplicate. If I take out the above example, and enter the mime type in either the server or the site, I then get a duplicate as well. I also found mention to this, and it seems there is some work around involving before the config inclusion as referenced above.
What's driving me the most crazy is that non of this is an issue on my local iis 7 machine. Does anyone have any suggestions, I'm floundering.
I built a Web API service that's hosted locally on my machine in IIS. I have an iOS app that I'm running via XCode that makes the call to the web service. The connectivity is there, and works. The iOS app successfully makes the connection to my published web service.
The problem is my web service is returning a non descriptive error to the client (iOS), so what I need to be able to do is step through the web service code while running my iOS app.
So, in summary:
I run an iOS app via my MacBook, and it connects to my .NET Web API service.
My Web API service is published to my local IIS, and is returning an error back to the client.
Breakpoints aren't being hit in Visual Studio - do I need to attach my Visual Studio debugger to a specific process? I've tried running my web service in debug mode while running my iOS app, to no avail.
How can I step through my web service code when running the client app (iOS) that accesses the web service?
Attach to process - http://msdn.microsoft.com/en-us/library/vstudio/3s68z0b3.aspx
Make sure "Show processes from all users" is checked, and pick w3wp.exe
You may need to hit the service once first to make sure its started.
To debug an app that's hosted by IIS, you want to attach to process (in Visual Studio it's Tools->Attach to Process or Ctrl+Alt+P) and pick w3wp.exe from the list (you might have to check a few boxes for the process to show up).
Another option is to use our free VS Extension called Conveyor
https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti
With it you open up IIS Express to remote connections on your network (or even the web through tunnelling).
Once you've done that you can debug the project directly from VS and connect to the Conveyor port number (or domain name via tunnelling) and debug as you would locally.
you can use Postman client.
First : run the API FROM visual studio
Second : go to postman put the url and add the parameter in body
More information : http://www.tutorialsteacher.com/webapi/test-web-api
this often works for me i generally list all of the processes in IIS with appcmd command
appcmd list wp
and pretty much you know which process to attach by seeing the names of the web services
if appcmd is not available please visit
Here for configuring this
I have written a WCF web service (not a web site, just JSON over HTTP) intended to run in Azure. I need to write tests for it.
I know how to do this, but it seems amateurish:
Run the web service,
Copy the root URL (e.g. http://localhost:81/)
Apply the root URL to my test project,
Run the test project.
I would like to be able to do this:
Hit F5
--> web service starts running
--> tests start running, automatically finding where IIS decided to run the service.
Is there a way?
There are 2 ways you can do this. Since you're using Windows Azure I assume you're using the emulator. Using the emulator means that the RoleEnvironment is available and you can get a list of roles, their instances, and their endpoints that are available.
var endpoint = RoleEnvironment.Roles["WebRole1"].Instances.First().InstanceEndpoints["Endpoint1"];
var siteUrl = String.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint);
This code will get the role named WebRole1, get the first instance on this role (you could use this to test if your web service supports load balancing) and get the InstanceEndpoint. The instance endpoint will give you all info you need like protocol (http/https) and the IP/port (these are things you configure in the ServiceConfiguration).
Note: This also works for processes running outside the emulator (like your test project). The only thing you'll need to do is reference Microsoft.WindowsAzure.ServiceRuntime.
Besides that you can also try to use the ServerManager class to find the current sites running in IIS, but I don't think this will work if you're running in IIS Express (which is also possible if you're working with Azure).
Fix the port number of the WCF project: go to the properties of your project, set "use dynamic ports" to false then specify a fixed number, for example 81.
Specify multiple startup projects in your solution: right mouse button on solution: select "set startup projects", then check the radiobutton "multiple startup projects", include your WCF service project in the startup list.
I hope this meets your needs...