Need some Instruction about WCF SOAP Service and ASP.NET MVC - asp.net-mvc

This is my homework, the hard one!
I need to build an online quiz, using ASP.NET MVC, include a desktop version (WPF) that can share the data with the web version using a XML Web Service - WCF. My teacher does not specific what kind of XML Web Service, after some research I choose SOAP because SOAP is a W3C recommendation and here is my plan:
A. When user write a quiz, in the Web site oe Desktop app, the submitsion will send data to WCF service. A list of different type of Item send to the server and save it to database.
B. When user do a quiz, all the data will submit to WCF service, and the total point is return by WCF service too.
After do some research on MSDN, I see that WCF can handle SOAP, but I can't find any document that show me how to do that. Either I'm very new to SOAP to process A and B action.
I have found some documents about using WCF with Entity framework and Code First:
http://msdn.microsoft.com/en-us/data/gg601462
http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx
These documents help me to build a Web service and retrieve data from my database, I think that is not in SOAP style.
SO now, I think what I need is:
Some recommends about what kind of XML Web Service.
Some documents show me how to handle SOAP with WCF if you say SOAP is ok for may app.
Thanks you alot for sharing!

I'm not going to do your homework for you fully... but I'll get you started on how to consume a WCF service the easy way.
First, WCF can use SOAP, JSON, or many other transport methods. By default if you are using a asp.net application and it calls a WCF service it uses SOAP. The XML that WCF uses is much more complex than a simple SOAP call you might hand build.
Second, to consume a WCF service from a asp.net app you can have Visual Studio create you "proxy" code that handles all the nitty gritty xml stuff for you.
To accomplish that, in Visual Studio in the Solution Explorer right click on the project name and click "Add Service Reference". Type in the URL of your service (http://localhost:9821/service.svc). It will auto discover the WCF service information there. Note the "Namespace". That Namespace is where the proxy code is kept.
If your service namespace was "MyService", then in your application code you would "imports/using" that namespace.
AKA: Imports MyService
Then your code would use it:
Dim serviceclient as new MyService.ServiceClient
serviceClient.myWCFFunction();

Related

Consuming a WCF service in .NET Core 2.0

I have a WSDL service which worked fine (and is still working in .net 4.x) and fairly newcomer to .NET Core 2.0.
I created the WSDL web service reference (The same steps followed as https://learn.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide)
My question is how to consume this service? Do someone know of a good tutorial? Any help would be greatly appreciated.
Thank you in advance
My question is how to consume this service?
The WCF Web Service Reference Provider Tool creates everything you need.
The client is automatically created with all the end-points in the service and any associated classes such as service parameters.
During the WCF Web Service Reference Provider Tool wizard you specify a namespace for the client, so if you entered CompanyName.Service you'd be able to create the client by typing var client = new CompanyName.Service.ClientName();
Please note that the name ClientName will be generated by the tool, and intelli-sense will you give you the actual name.
Once you have the client you can call any method on the service in the normal way. Such as:
var response = client.CancelPolicyAsync(cancelRequest);
Please check the link here:
Calling a SOAP service in .net Core
Calling a SOAP service in .net Core
How to Call WCF Services and Create SOAP Services with ASP.NET Core
Click here!
Your WCF service still is on .NET Classic - so nothing changed - you should consume it as always you do as regular WCF service.
What you have done creating WSDL web service reference - you have created client for Standard framework. Put it into separate Standard project. Then it can be referenced in core and classic frameworks aps.

WCF service to return JSON data to Web Application

I'm currently building a reporting service (WCF) - filled reports are produced using an Elastic Object which uses C# dynamics - I have written code to transform the object into JSON within the WCF service. The WCF service is hosted within a Windows Service and uses either named pipes or TCP bindings.
What I need to do next is to return the report object as JSON to an ASP.Net MVC web application which then just passes it through to the client without deserializing. I cannot have the client call the WCF service directly due to security issues.
Is this possible?
OK - This was fairly straightforward in the end -
I followed this post here, replacing my ElasticObject with the SerializableDynamicObject
(I didn't need the extended abilities of the ElasticObject)
This approach works nicely.

What is the difference between making calls to mvc controller methods and WCF WEB API Rest Service Calls?

What is the difference between making calls to mvc controller methods and WCF WEB API Rest Service Calls?
I can create an mvc controller post method that will allow me to execute any code i need.
I can also create a WCF Web API REST Service with MVC.
What is the difference between these two approaches to accessing data ?
More specifically what are the advantages of utilizing WCF in this scenario ?
WCF Web API handles XML and JSON out of the box whereas you'll have to create your XML and JSON "by hand" (read: using the Serializers) when using MVC - this is only one of the benefits of WCF Web API over MVC.
Another one is the level of separation WCF Web API offers e.g. implementing your service logic vs. content negotiation.
Yet you can easily use IoC containers and unit test your APIs being created using WCF Web API.
WCF Web API mainly has been created to build ReSTful API's whereas MVC just allows it to create them too - thus with WCF Web API you'll feel more comfortable creating ReST APIs.
If you're planning to start a project from scratch as an Web (ReST) Api, you should start with WCF Web API.
If you're planning to start with a Website that also offers ReSTful Services, you should suggest MVC.
You should also regard this tweet from Glenn Block.
You could accomplish a typical REST API with either one.
Usually the issue boils down to (1) what specific features you need and (2) what technology you are more familiar with.
There are some features of WCF that are really neat and not available in MVC (like binary serializations, the ability to host without IIS, et cetera) but those are not typically requirements in a REST API.
Overall I would say:
If you have an WCF implementation already in place and want to expose it as a REST API go for it with WCF.
If you already have an MVC site and want to expose it as a REST API stick with MVC.

How to use SOAP in asp.net mvc

A 3rd party site sends its notifications after my web application has completed some action in order to notify me of its success. Receiving a notification item requires a response back to the 3rd party server (URL) with the a containing the value "accepted".
I have never user SOAP and with the basic info found I'm a bit lost for the case of asp.net mvc. Are there any good links showing the principle of receiving and sending SOAP responses?
Tutorials / information may be presented in other languages such as java, asp.net (classic) or something. I need to get a general idea since googling on SOAP has not given me anything for the past few hours.
You need to learn a little about WCF. See the WCF Developer Center, especially the Beginners Guide.
What you want is to create a simple WCF service that corresponds to the WSDL that they will give you. You will need to implement only the operation (method) that they will call to notify you. You can host a WCF service in IIS along with the rest of your application.
The issue will be how to correlate the notifications with the page you're on in your MVC application.
I don't think this is specific to ASP.NET MVC really. If you have a WSDL for their web service, just use that to generate stub classes using either wsdl.exe or by adding a web reference to your project, then call the web service from your controller.
If I remember correctly SOAP is basically xml requests and responses.
You might want to look into WSDL (Web Service Definition Language) to avoid having to deal with raw data, and you would likely find a great deal of tutorials on wsdl as well.

How does ASP.NET MVC relate to WCF?

A Guide to Designing and Building RESTful Web Services with WCF 3.5, this article explains the foundations of REST and how it relates to WCF. MVC uses REST as the architectural model. I am guessing one can use the .NET MVC to create web applications that have both a front end and an API point, but I am not sure if the safe way of building the API is to build it with WCF and then use it in the MVC as a controller.
Please comment if the question is not clear, I will add or modify the text.
Theres actually a third option, ADO.NET Data Servies. Anyway, here how I see them.
MVC REST: Gives you full control over how to expose your data, you have to write all the code to get it up an running tho, e.g. serialization, deserialization, all the CRUD methods etc etc. Worht metioning that this being an MVC site means you are limited to exposing your service via IIS over HTTP(S)
WCF REST: More automation than MVC, a much more solid frameowkr than MVC REST, i.e. caching, security, error handling etc (basically all the stff you'd have to write yourself using plain MVC). Being WCF, you can host this in a variety of ways (e.g WS-, TCP) etc.
ADO.NET DATA SERVICES: The quickest way to get up an running with everthing ready to use, all you need todo is configure the global.asax, however you have to use an Entity Data Model, which you many not want to.
Personally, I would use either ADO.NET DATA SERVICES or WCF REST to build an API, consue that API in MVC site and then expose that API either directly, or by passing it through another layer.
ASP.NET MVC can serve as a REST endpoint for light services work, so I guess the answer to your question depends on how you define "safe."
Clearly WCF is designed specifically for creating REST endpoints, with all of the security implications that are implied thereof, whereas ASP.NET MVC is designed to create REST endpoints which can be used by ASP.NET MVC itself.
The following article shows how to create a web service using an ASP.NET MVC controller:
Create REST API using ASP.NET MVC that speaks both Json and plain Xml
http://msmvps.com/blogs/omar/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx
See also the following article from Phil Haack, which discusses an SDK the WCF team put together for users of ASP.NET MVC:
Rest For ASP.NET MVC SDK and Sample
http://haacked.com/archive/2009/08/17/rest-for-mvc.aspx
They are two different sets of technologies, only related by being built on .net
MVC is used to create websites and provides a model where URLs are routed to controllers and controllers deliver views to the user as the user interface.
WCF is a set of libraries in .net that are used to abstract the type of service (is it hosted in a windows service, as a webservice in IIS etc.) as well as the protocol (HTTP, TCP, MSMQ etc.) from the client and server which are communicating.
An MVC website may use WCF to connect to a web service, but that is just one of many options.

Resources