8

I have a class that is designed to work with a web service. For now, I've written it to query http://www.nanonull.com/TimeService/TimeService.asmx.

The class is going to be used by a legacy app that uses VBScript, so it's going to be instantiated using Namespace.ClassName conventions.

I'm having trouble writing the code to get bindings and endpoints working with my class, because I won't be able to use a config file. The samples that I have seen discuss using SvcUtil.exe but I am unclear how to do this if the web service is external.

Can anyone point me in the right direction? This is what I have so far, and the compiler is crashing on IMyService:

 var binding = new System.ServiceModel.BasicHttpBinding();
        var endpoint = new EndpointAddress("http://www.nanonull.com/TimeService/TimeService.asmx");

        var factory = new ChannelFactory<IMyService>(binding, endpoint);

        var channel = factory.CreateChannel(); 


        HelloWorld = channel.getCityTime("London");
E. Rodriguez
  • 717
  • 2
  • 6
  • 17
  • 1
    Check out this thread: http://stackoverflow.com/questions/54579/wcf-configuration-without-a-config-file – doblak Nov 16 '11 at 23:31
  • What do you mean by "the compiler is crashing"? What is the error? – Igby Largeman Nov 16 '11 at 23:33
  • Stupid question but thats an ASMX service not a WCF service right? – Jeremy Nov 17 '11 at 00:15
  • Darjan - I tried that, but I was unclear on the type to use, which brings me to: Charles - its bombing when attempting to resolve the Type in the ChannelFactory constructor. In Darjan's post, it's not clear to me either what argument goes there. Jeremy it is an ASMX service I'm trying to call. Thanks for your input. I feel like I'm almost there but missing something silly. – E. Rodriguez Nov 17 '11 at 00:22

1 Answers1

9

Darjan is right. The suggested solution with the web service works. The command line for proxy generation with svcutil is

svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://www.nanonull.com/TimeService/TimeService.asmx

You can ignore app.config, however add generatedProxy.cs to your solution. Next, you should use TimeServiceSoapClient, take a look:

using System;
using System.ServiceModel;

namespace ConsoleApplication
{
  class Program
  {
    static void Main(string[] args)
    {
      TimeServiceSoapClient client = 
        new TimeServiceSoapClient(
          new BasicHttpBinding(), 
          new EndpointAddress("http://www.nanonull.com/TimeService/TimeService.asmx"));

      Console.WriteLine(client.getCityTime("London"));
    }
  }
}

Basically that's it!

nbulba
  • 645
  • 2
  • 7
  • 17