consume secure web service asmx in asp.net mvc - asp.net-mvc

I want to consume secured web service in asp.net mvc, I need to create proxy class to this service
I tried to use wsdl.exe tool but it gave me the following errors
There was an error downloading
The request failed with HTTP status 401: Unauthorized.
is there another way to create proxy class
or there is another technique to call this secured web service in my application

It looks like the WSDL requires authentication in order to be downloaded. I suppose the Web Service also. The WSDL.exe utility allows you to specify the username and password to be used when downloading the WSDL. So go ahead, talk to the author of the web service to understand what account you need to use in order to access it and then try the /username and /password parameters:
wsdl.exe /username:john /password:secret http://example.com/foo.asmx?WSDL

Related

Blazor Web Assembly connecting to OAuth via Implicit Flow

In my blazor web assembly project, I have to connect to a Web API that doesn't implement OIDC.
I read on the aspnetcore github thet they made the choice to implement only OIDC connections...
I think I have to write a custom implementation of RemoteAuthenticationService and add it via the builder.Services.AddRemoteAuthentication method, but can't understand how to do this.
Reading the current implementation of RemoteAuthenticationService doesn't help.
The only thing I have to do to connect the Web API is to call this URI :
https://<webapi>/oauth/Authorize?client_id=<MyClientId>&state=<State>&scope=read&response_type=token&redirect_uri=<RedirectUri>
The user fill in the form and get redirected in my blazor app via the RedirectUri, having the accessToken in url parameters.
Then I have to add the accessToken in the headers of all Web API Requests, but I found how to do it via AuthorizationMessageHandler.
How can I implement this flow with Blazor Web Assembly ? Do I search in wrong direction ?

Separating Web Api and Web Site

i'm new to asp.net web api, owin, and everything related to it.
I'm trying to find the best way to do this scenario:
1 - Web api to have all the connections and rest service
2 - Web site to show data to user on a browser using the restful service
3 - An mobile app that have some functionalities like the web site and access the restful service to get all the information
My doubt is: what's the best practice related to the login? I'll use owin/oath2 with Identity to login, but since it's going to be implemented on the web api, the login/register/forgot password should be on the web api directly (like the project template does) or should i move most of the functionality to the web site? Of course its easier to leave in the web api, but if i do it, i must duplicate my razor templates just to call the login part. Can someone give me a path to follow?
Thanks!
the answer is not, your web api should not have any html or js or css file, only the services that your need, the web api exposes the functions to register the user, next when you have to do request, you must Send a token, you can obtain the token using the URL that you have configure in owin, the URL is like /token and Send the username and pass.
Regards,

How to secure a WCF Service

I have a WCF service hosted in IIS. I have another website hosted in asp.net mvc. It is a public web site. I want to secure my WCF service so that it won't be accessible from any applications other than my MVC application, or which I give access.
Can I do this using forms authentication?
Update:
I had gone through several examples, but I couldn't get an effective one. I dont want to use ssl. Login feature is not there in my web spplication. If required, a programitic login can be implemented. All I need is, deny access if the service is not called from my website. I've done this in web service using forms authentication. But here, the httpcontext is null.
Yes, you can. WCF calls go through the same pipeline so that if you check for specific principals (usernames or roles), your checks will fail/succeed depending on the Forms cookie.
More details in my blog entry
http://netpl.blogspot.com/2010/04/aspnet-forms-authentication-sharing-for.html
where I show how to share the forms identity between a web app and hosted silverlight app which calls WCF services.
In case of yet another type of the client application, the way you get the cookie value at the client side can vary. Silverlight just inherits cookies from the web application it is run from.
Assuming your client is a console application, you could even expose an unguarded method from the WCF service which accepts loginname+password and returns the cookie to the client. This way, the console application would first call this unguarded method to login the user and then, using returned cookie, would call other WCF services guarded with forms authentication.

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

WSDL and WEB Service

I am new to web services even after watching a lot of videos and reading a large number of tutorials on WSDL I am unable to understand how to get URL for a method of web service from WSDL. the WSDL file I am provided with is this http://cons.epackagepro.com/m/Service.svc?wsdl I want to call a login method of this web service. Can somebody explain that how to extract exact url for a web service/web service method from a WSDL file and how to pass parameters to a web service (in this particular case I want to call login). All the tutorials I watched tells that service tag of WSDL file has an address tag which tells about the url of the service but this WSDL does not contains one.
One last thing, can I call this service with soap, even soap is not used in binding. And what if I want to call it using HTTP GET / HTTP POST method, how parameters will be provided.
My main concern is how to get url of a web service / web service method from WSDL? The platform for which I want to use it is IOS.
Thanks in advance.

Resources