Is it possible to create a SOAP API using C# and JavaScript - c#

I am looking to create a SOAP API using C# which I can then call using JavaScript. I use C# regularly but do not have any experience with creating API's. I would like to call the API using JavaScript as this will be used to submit form data from multiple websites not maintained by us.
If there is a better solution than SOAP I am open to suggestions.
If anyone can point me to examples or has any examples they can share I would appreciate it.
TIA
BrianKE
EDIT: I should have mentioned that I would to deploy a solution that will allow form data from multiple websites, not under our domain, to submit data directly to our database, hence the API. Perhaps there is a different way to handle this other than an API that I am not aware of.

If there is a better solution than SOAP?
If you are going to consume the API from javascript JSON is preferred. You may checkout this example which illustrates how to expose a JSON enabled WCF service for consumption from jquery AJAX.

Yes. You can.
Barring small issues/restrictions with XHR, it's perfectly "fine" to consume SOAP services from JS. The biggest issue is "dealing" with the XML, which can be more cumbersome than JSON (but it isn't bad if you use the correct tools such as XPath extractors). For my projects I use a small wrapper setup for the AJAX/XHR/SOAP call (not WSDL generated) that can take custom encoding/decoding functions.
Google searches shows several promising results/examples including JavaScript SOAP Client.
Note: If you need cross-domain access there are several methods including a proxy or the newer cross-domain XHR support (however, these require client and/or server support) or, depending on client, just really relaxed settings. These cross-domain considerations are generally no different than if using "REST" or other web-service APIs.

Related

Guidance for creating client package for my api/webapi

I've tried, but I couldn't find any info about it.
Let's say that I have some webapis for my company that other devs (or qa) are going to use in theirs applications, and for easier use of my apis I'd like to create a library with client so that I can control how other devs are communicating with my api. So basically they can just install this package, add webapi url to configuration, inject necessary dependencies and use it. Is there any pattern, guidance etc. for creating such packages with client? I'm not talking about good practices how to create web api, rest api etc, but just this specific client package.
I've tried googling some tips or guidance about this (or maybe just generic instructions), but all I could find is how to create REST API...
You can use NSwag. With NSwag you can:
Generate Open API/Swagger specification from your Web API controllers. It is just a JSON document describing you API
Include an Html/JavaScript front end in your Web API application where users can see your API and invoke it.
Generate C# clients to invoke your web API.
Useful links:
https://github.com/RicoSuter/NSwag
https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-nswag?view=aspnetcore-7.0&tabs=visual-studio

Working with XML and AngularJS - special web method to return JSON how to implement

I was recently assigned the task of creating a login page for my company and they're requiring that I use angularjs for the client side application.
The authenication services are asp.net web services that have already been coded, and return xml because of another service that also uses them.
I notice that AngularJS wants JSON data for it's return value.
I need a way of using AngularJS http methods get and post that will work with data from and to the web server using SOAP. My recent attempts have consisted of trying to get the xml back and then convert it to json on the client side.
Converting on client-side can potentially have problems and so I would prefer to keep all conversations on the server-side.
My solution would be something like have all my web services working as normal. Then have one web service that can take another method in as a parameter and call that method in code and return a json string.
Can anyone give me some input on this. My reason behind not wanting to simply change the web services to return json is because other applications use this service and are expecting xml, also there are more than 1000 web methods in place.
I may have found a solution I am going to work towards. However, if any viable options are still available that would simply add a new method to the list of web methods that would be great. Talking with the developer that wrote all the web services I will need to be using it would be simpler to convert the xml to json on client-side. I am also looking into some angular modules that people have written for get, post for soap services.
Found here
After lots of digging around the best option for me is to use this code Here. I can make the call easily and once I get the xml back just do angular.fromJson(angular.toJson(response)).
If ASP.NET WebAPI is used on the server side it may be sufficient to add an Accept header with the value application/json to the HTML request. It tells the server to return JSON instead of XML.

how to make a service, SOAP web service in .net?

Please forgive me for this basic and a little theoretical question as I dont know much about web services.
I m not refering WCF service, I am reffering simple service in .net / C#. I want to know how to know is it soap or rest service ?
How we can change this type from Soap to Rest and vice versa ?
Thanks
XML Web Services (aka classic/legacy ASMX web services) should not be used for active development. If you must, there is a nice walkthrough on MSDN for adding Web references in more recent versions of Visual Studio (> 2005).
On the other hand, if your web service is truly Restful then you won't be able to create the equivalent of a service reference to it. You'll need to either use the HttpWebRequest, WebClient, or the new HttpClient from .NET 4.5 (also available from the Rest starter kit which is depreciated as well).
As an alternative if you are looking to implement a client that is able to handle both situations, I would recommend HttpWebRequest to POST to the SOAP (non-WCF) service. The problem with this method is you'll likely have to wrap the request in the SOAP wrapper yourself. Luckily there are examples of doing so on the net that you can at least use as a starting point.
ASMX services are build upon SOAP. REST is simply a HTTP based, You can access(or call) your business resources the way you access the normal URLs.
For ex in products catalog system, by using asmx you create set of functions to add,update,delete products. like addProduct(),updateProduct, etc..
But in REST, you will be having single point of access, like http:\mysystem\prodcuts. To retrieve,add,update,delete products, you will be using respective HTTP verbs (GET,POST,PUT,DELETE) on the same URL.
so,technically it's not possible to convert asmx(SOAP) service to rest...

How could I use C# to send and receive data from Web Service directly?

As a tester, i was asked to test a web service via C#. I've no idea how to use C# directly to send data to Web Service. Could you please give some samples about it? BTW, please do not use the proxy method.
Thanks
Sut
I'd recommend using SOAPUI if you are trying to test SOAP web services directly. Trying to call them using HTTP requests and then parsing the resulting SOAP is going to be quite a chore if you have to use C# and not use the imported proxies.
Note: You'd be much better of if you talk to whoever asked you to do something... instead of asking strangers.
In most cases call to web service is simple HTTP POST or GET. There are plenty of ways to perform it directly - i.e. "How to: Send Data Using the WebRequest Class" ( http://msdn.microsoft.com/en-us/library/debx8sh9.aspx).
And response from web service is generally XML - again plenty of classes to read including XmlDocument and XDocument.

Is there a WCF Rest C# Client Generation Tool?

Before I venture down the path of creating one, I was wondering if anyone knows of a utility program which will take the REST Help page of a WCF Rest Service and create the relevant Client for C# consumption.
Similar to what svcutil.exe does for WCF Services or what wsdl.exe did for web services but for WCF REST Services
Kind Regards,
Andrew
EDIT Some more detail:
Please see this link: http://msdn.microsoft.com/en-us/library/dd203052.aspx
In the restful service using the WCF Rest Starter Kit Preview 2, they supply types which will be serialized. But My intention is be able to create clients form the help page which describes schemas. Clients could then be created for C#, JavaScript, ActionScript etc.. shearly as a strongly typed version of the restful service, not a requirement or necessity. It is a program or uitlity I am wondering exists which does this
I think you might be looking for the WebChannelFactory. It can generate a channel class based on a WCF-attributed REST interface.
Well, there will not be any use even if you would like to abstract. ALL Rest services can use HTTP verbs like GET, POST, PUT, DELETE
So, basically what your client can have is only a static class which can accept the end point, network credentials, a name value collection which needs to be passed and the verb to use.
This would be more of a utility class rather than a client.
I don't remember seeing WSDL or some contract based on which we can write clients for the REST services.
I hope you don't spend too much time basing your code on the current help page of a pre-release piece of code. Are you even sure this help page provides all the information you would need to produce clients?
Also, have you seen Prerelease 2 of the WCF REST Starter kit yet? If no, go look. There's new client-side technology in there.
Why would you create clients for a RESTful service? You don't need one - you just need to be able to initial HTTP requests. If you would like to call the same operations via SOAP or some other method then create a new endpoint for the service and a new contract and expose mex for it so that svcutil can consume it.

Categories