c# Webservice Consumed by PHP client - c#

What is the best way to create WebService using Visual Studio which can be consumed by PHP or Java client?
The WebService must require authorization.
I have some expierence in creation of WCF Service with custom authentication (see: http://jaliyaudagedara.blogspot.com/2013/07/set-wcf-service-authentication-to-use.html )
and I know that PHP programmers have problems to pass credentials.
Are there any methods of protection of WebService that are compatible with PHP world?

WEB API 2 Is Microsoft's Latest technology for Hosting Web Services.
It is compatible with all official Standards. (XML, JSON, REST ) etc.
There is no reason any platform to have any difficulties connecting to such an API.
You can pass data for identification just by initiating a POST request with a JSON Object.

Related

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...

Calling basic authentication java webservice with C# Client

I have a c# client application calling java web services. Everything works great but now i need to send some authentication data since we are trying to restrict who calls the web service. The java web service expects basic authentication.
How do i go about providing this in my c# client? I am not using WCF or WSE, just plain webservice (using Add Web Reference).
Here's a link for the solution i found in case some one needs it. I was able to fix my issue by modifying some of the stuff in the suggested article.
http://www.c-sharpcorner.com/UploadFile/pchandraker/1052/

When I Make my (ASMX) web service accept/return JSON instead of XML, is it no longer considered SOAP?

Just trying to wrap my head around SOAP vs REST. We currently have some asmx web services, mostly used between our own JavaScript and server code (not a public API). When I specify my method as a ScriptService and specify a ResponseFormat of Json, is it still considered just a SOAP service? It still doesn't feel RESTful to me, but maybe thats because of the way my "resources" are designed (not well/fully represented by rest).
EDIT: Reading more I might be confusing the format (JSON vs XML) with the fact that most descriptions of the SOAP protocol tie in XML. For example, wikipedia states:
It relies on Extensible Markup
Language (XML) for its message format
To me logically that says if I'm using JSON I must not be using SOAP.
This isn't exactly what you asked, but ASMX services are not RESTful if you're calling them from JavaScript and retrieving JSON. You must make a POST request to ASMX services to get JSON out of them, even if the request is idempotent and only retrieves data. In a RESTful API, a GET request would be used in that case, not POST.
That's not to say that the lack of RESTfulness is an actual problem for a private API. I've found ASMX services as a JSON-based service layer for AJAX callbacks works great in practice.
You define what kind of requests are made to you web service (asmx). Many protocols are allowed:
HTTP POST,
HTTP GET,
SOAP 1.1,
SOAP 1.2,
etc... OR you can block any of them.
When you call the web service with javascript you can use POST or GET. It doesn't matter. The trick is what type of content you tell the service to return in these calls. You can tell the service to send you JSON or you can tell the service to send you XML.
When you create a service client in Visual Studio to connect to a ASMX service, Visual studio will try to access the WSDL for the service and the client will be in charge of generating the SOAP envelopes to communicate with the service and in this case you will send and receive XML because thats what the client and server have agreed to use to communicate.

Calling a php SOP webservice from c# that does not support wsdl

Can any body have idea how to consume php soap web service that have no support wsdl.
I want to add reference in .Net to generate client but failed.
When i saw in browser with ?wsdl it shows message wsdl is not supported.
Simply said: you can not. WDSL is there for development environments to know how to deal with a web service. Whoever wrote the web serivce made sure (or was ignorant enough to now know) that it is not usable from any tooling support.
You might want to consult the PHP: SOAP Manual and verify that you wrote the PHP webservice correctly.
And you can also look at this example: PHP Webservice and C# / .NET SOAP Clients
You need to configure the SOAP Service to support WSDL
(Web Services Description Language) An
XML-based language for describing Web
services and how to access them.
Otherwise .NET won't know what or how to use it.

To consume a RESTful web service in C#, should I use HttpWebRequest?

How do I consume a RESTful web service in C# code?
NOTE: by RESTful, I mean non-SOAP. For example, in the flickr API you can call their web service as follows to return JSON data:
http://api.flickr.com/services/feeds/photos_public.gne?tags=cats&tagmode=any&format=json
Do I simply use HttpWebRequest?
What if I'm using a web service that takes POST parameters? Would that use HttpWebRequest also?
Is there any benefit to using WCF on the consumer side?
WCF provides a unified programming model for communication, so if you later decide that you do not want to use REST or you want to provide an extra type of endpoint for example SOAP, you only need tp change the configuration.
Take a look at REST for WCF:
http://msdn.microsoft.com/en-us/netframework/cc950529.aspx
Their is a demonstration and labs in the .NET Framework 3.5 Enhancements Training Kit, which provides two labs based around creating, servicing and consuming RESTFul services. The above link is the best MS combined resources of REST services.
Bob.

Categories