0

I'm new to web services in ASP.NET. Been trying to get my head around it recently. Here are my questions.

  1. The Web Service item (.asmx that you can add to your project in Visual Studio), does that only generate an XML service (generate XML output)? What about JSON?

  2. When I add a web reference to my project, and I get prompted to specify a URL, what kind of service does that have to be? For example, when I enter http://search.twitter.com/search.json?q=twitter - it doesn't work (nothing gets fetched).

  3. After you create an .asmx service, how is this consumed through a non-.NET technology like PHP or JavaScript?

  4. If I were to create a web service in another technology (PHP/ColdFusion), what would be the requirements so that I could easily add a web reference to a .NET project to be ready for consumption?

  5. When do you ditch creating a Web Service (.asmx) and create a Generic Handler (.ashx)? What's best practice?

SaltProgrammer
  • 1,045
  • 2
  • 13
  • 29
  • 2
    Each one of those questions is probably too big in scope individually for this site, much less all in one question. To get you started, I strongly suggest googling "Web Services SOAP RCP vs. REST" The asp.net web services are SOAP/RPC. You need to understand the differences between the two before you can even start making sense of the other questions. – David Jan 25 '12 at 22:43
  • Thanks, but I feel like a lot of these are .NET specific and tooling in Visual Studio. – SaltProgrammer Jan 26 '12 at 00:05
  • You shouldn't be using ASMX at all. Use WCF. – John Saunders Jan 31 '12 at 16:39

3 Answers3

2

The answers were provided here: http://forums.asp.net/p/1762729/4808974.aspx/1?p=True&t=634636052163539362

1.When you add web reference (.asmx) to your project, then it will generate three different type extensive files, they are reference.cs, .disco and .wsdl. and the web service name and value (something like the following) will be added in the project config file, The Reference.cs is the actually generated proxy class which is mainly used to call web service on client side.

For example:

<applicationSettings>
    <WebApplication3.Properties.Settings>
        <setting name="WebApplication3_localhost_WebService2" serializeAs="String">
            <value>http://localhost:8776/WebService2.asmx</value>
        </setting>
    </WebApplication3.Properties.Settings>
</applicationSettings>

As for JSON, it is a lightweight data-interchange format, and completely language independent. It is a collection of name/value pairs and an ordered list of values, we usually use Jquery to call JSON web service and REST Service, and set its contentType to "application/json; charset=utf-8" and dataType to "json".

2.Usually ASMX Web Service (.asmx file) can be added to consumer project using add web referecne, we'd better add the url of web service which end with .asmx, something like this. http://localhost:8776/WebService2.asmx

3.There are several ways that you can call .net web service from non-net technology, you can send request soap message to web service, for more about this, check this article. and also some development tool provides option that you can add wsdl reference as VS tool only you specify the WSDL URL, for this, check this article.

4.If you can browser the web service in IE browser, then you can add '?wsdl' at the end of web service url, then in VS tool, you can add web reference to that wsdl url, and then you can consume that web service, please check this article.

5.As for Generic Handler (.ashx), it mainly used in the following scenarios (1)Apply security mechanism, (2)URL rewriting, (3)Filter something in the request that is send to IIS. and it depends on your requirement that you want to choose web service or .ashx.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
SaltProgrammer
  • 1,045
  • 2
  • 13
  • 29
1

1) For the syntax to get a json asmx service to work, take a look at this post

5) The new way to go is WCF

Community
  • 1
  • 1
frenchie
  • 51,731
  • 109
  • 304
  • 510
1

Regarding question 4, I got to consume ProcessMaker Web services from ASP.Net . ProcessMaker is an open source workflow solution, which provides integration throuhg SOAP webservices developed using PHP.

Nathan
  • 2,705
  • 23
  • 28