views:

201

answers:

1

I'm taking my first baby steps into consuming web services. Here's my situation:

I'm writing in .NET 3.5 for an existing corporate intranet website. I need to add a call to a web service, passing account data and getting a response.

I am able to add a web reference to the .wsdl file and have Visual Studio generate the Service Reference class.

So, here's my question - is it easier to use WCF in this situation, or should I use the baked in ASP.NET web services architecture?

I tried to get the web services working using the following code, but was unsuccessful. In this code, the ProgramServiceClient is the name of the service class generated for me by VS using the wsdl file. Again, I am very new to this, so any pointers would be very helpful!

    var client = new ProgramServiceClient();
    Int64 acct = 123456781234
    var requestMetadata = new RequestMetadata();

    var response = new GetProgramResponse();
    var request = new GetProgramRequest
                      {
                          AccountId = acct
                      };

    client.GetProgram(requestMetadata, request, out response);
+5  A: 

See How to Consume a Web Service.

You should use WCF for all new web services development with .NET. WCF is "baked in" to .NET. What you refer to as the "baked in ASP.NET web services architecture" is the previous, old, and stagnant web services architecture.

As to the specific code you posted, it's good that you're posting specific code, but you should also post the specific error messages or exceptions you receive. In particular, if you get an exception, then post the complete exception, including stack traces and InnerException instances. Catch, and then display, ex.ToString().

John Saunders
+1 absolutely: WCF just offers SO MUCH MORE flexibility and power and options - anyone starting NEW today shouldn't even have to think WCF vs. ASMX - the choice is totally clear!
marc_s
John, thanks for the concise and informative answer. I got everything running, and now I'm just dealing with errors being thrown by the actual service, which is all just getting the request formatted properly. You got me up and running, though. Thanks!
Mark Struzinski