REST web service with asp.net - asp.net

How can I add a reference to the REST web service to an ASP.NET application? The REST is generating the WADL file. How can I add a reference to my application . I tried the regular way, using Add Web Reference option, but that gives me an error.

You already asked this question a few days ago. You cannot do it, nor should you try to do it. One of the major objectives of REST is to decouple the client from the server, if you start generating proxy code on the client based on WADL you are likely to embed information into the client that with create coupling.
A REST message is supposed to be self descriptive therefore WADL should be completely unnecessary for a correctly built REST service.

Related

Interacts with QT using web

I need to transfer data from a QML project to the web and I don't know how to do with that.
I have a QT client and I want to make the industrial data update on the website at the same time. If I need to create a HTTP client based on QT in the project? I am so confused.
And I also need to use web to send message to my QT project, how my backend work with? A micro-service?
If my QML project needs to add a HTTP server?
Sorry for my stupid question but I have been thinking for a week.
You'll need to upload the data to the web server, through the suitable API / web page.
If it's already possible to add data manually, then you can do the same programmatically with Qt, through HTTP requests.
If not, you'll need to get this interface done, and it's probably beyond your current question.

Angular 4 application receiving ViewComponent ASP.Core server responses

I am trying to build a single-page application with an ASP.Core + Angular 4 stack. The server is supposed to provide view components, which will be rendered client-side and populated with additional data.
The best way to create components would be utilising ViewComponent mechanic on the server, which allows me to effectively create HTML layouts and populate my HTML components with data from DB. Alas, I have not yet found a way to transfer the data to my Angular 4 client app. The ViewComponents are not static resources, meaning I (most likely) can't transfer it as JSON-data, and even if I could, I'd have to teach my client how to unwrap it back into html, which would increase the load on the client.
I have confirmed that JQuery calls can be made to receive IViewComponentResult responses, but I am yet to find a way on how to achieve same results in an Angular component. Any help would be appreciated.
Usually with this stack you use .NET Core as the backend meaning you use it to write the Web API code which interacts with the database. The Angular side of things would have services which call the Web API via http methods and present/manipulate the data in component.html/.css/.ts files.
You can read through a guide such as this to get an idea of the structure and flow of the stack. Everything you mentioned in your 2nd paragraph can be achieved through this architecture without the worry of transferring ViewComponents.

Using webservices with in .Net project from local namespace is valid approach or not?

I am newbie in webservices of .net, i am implementing a project of .net with backend in webservices as i got impressed with the benefits and portability of this architecture.
But the confusion is, i want to know the way i am adopting is right or wrong. I have made services with in my project and calling them from code behind classes, where as my service is implementing the database code. I am attaching the screenshot for further explanation.
Not really, when you do this you are calling the classes directly rather than as a service call. This is liable to cause you issues (e.g. if you set up one of your methods to return a certain HTTP response status for example).
If you don't want this to be a service call, then you would be better extracting the logic from the service method into a business layer and have both the service and your page call that code.
If you do want a service call, then you need to add a service ref to your project that points to the service and call it through the generated proxy.
Your approach makes no difference of using a C# class vs using a webservice.For this approach You can use a class instead of a webservice.
Use web services instead of C# classes for the following cases.
You want to expose some functionality to outside world/consumers/other applications
You want to decouple parts of your system so that they can be changed without affecting other parts of application
You want to do make your application scaleable, so you create webserices and deploy those on different servers

Prevent generation of proxy classes in Reference.cs when adding/updating a web reference

I have a web service and a client. The classes used in parameters and return types are in a common DLL shared by both. However, whenever I update the web reference, visual studio generates copies of the classes with the same names and public properties and methods. Then the solution won't compile because the client code tries to use the versions in the common DLL. I can solve the problem by deleting the "duplicate" classes every time I update the web reference, and adding a using statement to point at the common dll's namespace. Is there a way to fix this permanently?
UPDATE: See my comments below. This is a "feature" of asmx web services. There is no way around it other than one of the following:
1) Use a more modern type of web service.
2) Don't use a common DLL
3) Manually fix every time you update the web reference, as in the original question above.
This is a "feature" of asmx web services. There is no way around it other than one of the
following:
Use a more modern type of web service.
Don't use a common DLL
Manually fix every time you update the web reference, as in the original question above.
Sources: Other stackoverflow questions:
"Reuse existing types" is ignored when adding a service reference
How does Visual Studio 2008 and svcutil decide which types to re-use from referenced assemblies when generating a web service proxy class?
I had the same problem, but I had neglected to add the reference the correct assembly with the request/response types in my client. Once I added that reference, and ensured that the "Reuse types" checkbox was on in the Add Service Reference dialog, it worked properly.
There`s no way to do that.
However, I think we have a design problem here. When we create a web service, we expect that our clients don't need to reference any dll from us. Only the types exposed by the web service should be enough for their use (web services are all about interoperability, imagine your client app written in Java, you can't reference the .NET dll).
That's why these types are created when you reference a web service. In my opinion, you should only rely on the classes generated by the web service in your client app. Remove the reference to the shared dll from the client project.
This doesn't direct answer your question, but provides an alternative for your issue.
In the domain class, set AnonymousType=false to prevent generating class with prefix unexpected when adding the web reference
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = false)]
but this only ensure that the class, auto-gen in Reference.cs has the same structure as the domain class.
A way to walk aroud this is to serialize/deserialize to the domain object.

ASP.Net MVC4 self-hosted API on same port as website

Dear developer friends,
I have developed a self-hosted API in ASP.Net MVC4 (e.g. http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx), because I needed a solution where I could upload super large files. This works smoothly.
Now I want to upload files to my newly written API through the Bluimp JQuery Upload component.
This works fine, except for some small flaws:
- the progress-bar is not showing
- JQuery raises an error: Unsafe JavaScript attempt to access frame with URL...
It seems clear that this error is raised, because my API runs on another port than the web application, and ajax calls cannot be made over cross domains / ports.
I have already added the forceIframeTransport: true parameter to the fileupload component call. This does some good - without it I cannot upload files at all (because the component tries to upload with an ajax call).
So.. I figured that if there's some way to run my self hosted API on the same port as my web-application (with explicitly defined routes), my world will be happy and shiny again. However.. I'm not quite sure whether this is possible at all..
Unfortunately a proxy from my ASP.Net application will not help me here, as I wrote the API to avoid the IIS limitations (regarding maximum upload size). Using my self hosted API as proxy might to the job, but I think this is a bit.. overkill?
Anyone? Thanks in advance!
Yahoo! Solved it!
var config = new HttpSelfHostConfiguration("http://localhost:49302/api");
In other words - the web api ONLY works when the url starts with /api. All other requests are picked up by my MVC4 web application. But they run on the same port.
So to answer my question: yes it's possible. Just add a root directory.

Resources