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");
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With