以编程方式创建.NET WCF服务端点 [英] Programmatically create endpoints in .NET WCF service
问题描述
我有被设计为具有Web服务工作的一类。现在,我已经写它来查询<一个href="http://www.nanonull.com/TimeService/TimeService.asmx">http://www.nanonull.com/TimeService/TimeService.asmx.
的类将被使用的遗留应用程序,使用的VBScript,所以它要使用Namespace.ClassName约定被实例化。
我无法写code获得绑定和端点与我的课的工作,因为我将无法使用的配置文件。我所看到的样品讨论使用svcutil.exe的,但我不清楚如何做到这一点,如果Web服务是外部的。
任何人都可以点我在正确的方向?这是我到目前为止,编译器崩溃的IMyService:
VAR结合=新System.ServiceModel.BasicHttpBinding();
VAR终点=新的EndpointAddress(http://www.nanonull.com/TimeService/TimeService.asmx);
VAR厂=新的ChannelFactory&LT; IMyService&GT;(绑定,终点);
VAR渠道= factory.CreateChannel();
的HelloWorld = channel.getCityTime(伦敦);
Darjan是正确的。建议的解决方案与网络服务工作。对于代理生成与SvcUtil工具的命令行是
svcutil.exe的/语言:CS /out:generatedProxy.cs /config:app.config http://www.nanonull.com/TimeService/TimeService.asmx
您可以忽略的app.config,但添加generatedProxy.cs到您的解决方案。接下来,你应该使用TimeServiceSoapClient,一起来看看:
使用系统;
使用System.ServiceModel;
命名空间ConsoleApplication
{
类节目
{
静态无效的主要(字串[] args)
{
TimeServiceSoapClient客户端=
新TimeServiceSoapClient(
新basicHttpBinding的()
新的EndpointAddress(http://www.nanonull.com/TimeService/TimeService.asmx));
Console.WriteLine(client.getCityTime(伦敦));
}
}
}
基本上就是这样!
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!
这篇关于以编程方式创建.NET WCF服务端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!