Programmatically create endpoints in a .NET WCF service

I have a class that is designed to work with a web service. At the moment, I wrote it for the request http://www.nanonull.com/TimeService/TimeService.asmx .

The class will be used by an obsolete application using VBScript, so it will be created using the Namespace.ClassName conventions.

I am having trouble writing code to get the bindings and endpoints working with my class, because I cannot use the configuration file. The samples I saw discuss using SvcUtil.exe, but I don’t understand how to do this if the web service is external.

Can someone point me in the right direction? This is what I have so far, and the compiler crashes in 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"); 
+7
source share
1 answer

Daryan is right. The proposed web service solution works. The command line for generating a proxy server 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, but add the generated Proxy.cs to your solution. Then you should use TimeServiceSoapClient, 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, it is!

+8
source

All Articles