Consume ASMX from MVC app - asp.net-mvc

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!

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.

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

Reference web api from a different project

I am developing a MVC app. I want to develop some web api's so i can use them from other projects.
Can this be done as currently when i do create a web api project it creates all the controllers and views etc.
Also would this be the place where you setup the types e.g. contact type which contains all the objects for a contact e.g. name, address etc.
Just need to get it right before i get my head into it.
Thanks
You could perfectly fine define your Web API controllers (deriving from ApiController) inside separate projects (class libraries). The Web API is normally RESTFul and Web API controllers don't return views. They return models which are normally XML or JSON serialized. You could even host the Web API outside of an ASP.NET application in its own host which could be a Windows service or Console application for example. You don't even need IIS. The following article described a self hosting scenario.
As far as the consuming client side is concerned, that could be absolutely any kind of application ranging from desktop application to another ASP.NET site. The client application could use the native HttpClient class to consume the WEB API or any other HTTP capable client such as WebClient or even HttpWebRequest. The client could even be written on some other non .NET platform. All that is required is the capacity to send HTTP requests.

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();

Resources