Consuming a WCF service in .NET Core 2.0 - asp.net-mvc

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.

Related

Consume Secured web service in Asp.Net MVC

I'm working on asp.net mvc
I want to consume secured web service in my project
In previous I can consume unsecured web service (asmx) by calling wsdl to create proxy class ,now
I tried to create proxy class for the service by using wsdl.exe by using the following formula
Wsdl /language:language /protocol:protocol /namespace:myNameSpace /out:filename /username:username /password:password /domain:domain
But I had the following error
Error: There was an error processing 'https:// .asmx?wsdl'.
- There was an error downloading 'https:// .asmx?wsdl'
- Unable to connect to the remote server
- A socket operation was attempted to an unreachable network ??.???.???.??:???
Can you tell me how can I consume secured web service in my project
Yara
I dont know what sort of service you are talking about but I suspect you are Adding it as a Service/Web reference. If thats the case then assuming its called WebService1 and that the security you are talking about it basic authentication then:
WebService1 svc = new WebService1();
svc.AuthenticationHeaderValue = new WebService1.AuthenticationHeader();
svc.AuthenticationHeaderValue.UserName = "username";
svc.AuthenticationHeaderValue.Password = "password";
Try that. As I said I dont have much info on what you are trying to do so its a guess.
First of all it doesn't matter you are in MVC or any other technology.
If you can call https webservice using simple code, it will do wonders for you.
So first try calling simple HTTPS web service, google and play around it.
For learning purpose and to gain more knowledge, check these links
How to call HTTPS web service method from a .net console application?
Calling a https web service (C#)
http://support.microsoft.com/kb/901183

Consume ASMX from MVC app

I have a legacy asmx service (which I have never worked with them). I want to consume it from an MVC application.
First I Add Service Reference with the following wsdl http://thisisanexample.com:1928/WSTest/Service.asmx?wsdl.
The service generated some classes:
Request and Response classes for each method
ServiceSoap interface
ServiceSoapChannel interface
ServiceSoapClient partial class
I have been trying to consume the service with ServiceSoapClient like
ServiceSoapClient client = new ServiceSoapClient(); // or ServiceSoap client = new ServiceSoapClient();
client.MethodName();
However using client seems not work because it doesn´t compile.
EDIT: It does compile but when I write client. it does't show any operation to use..
How can I consume this asmx web service?
Thanks!

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.

Need some Instruction about WCF SOAP Service and 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();

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.

Resources