WCF - 在没有 app.config 的情况下使用 [英] WCF - use without app.config

查看:24
本文介绍了WCF - 在没有 app.config 的情况下使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用 WCF 服务的 SharePoint 工作流.只要工作流在 IIS 下运行并且没有转移到计时器服务,这就可以正常工作.

I have a SharePoint workflow which calls a WCF service. This works fine so long as the workflow runs under IIS and is not shifted to the Timer Service.

问题是计时器服务无权访问它需要从计时器服务的上下文设置 WCF 连接的 web.config 设置.

The problem is that the Timer Service does not have access to the web.config settings it needs to setup the WCF connection from the context of the Timer Service.

在 ServiceModel 客户端配置部分中找不到名称为 endpointname' 和合同为 'servicecontractname' 的端点元素

我正在设置 WCF 在代码中建立连接所需的所有信息(并覆盖 web.config 中设置的值)

I am setting up all the info WCF needs to make the connection in code anyway (and overriding the values set in web.config)

我的问题是,我可以完全绕过这个配置吗?我宁愿不依赖多个设置文件并使它们保持同步.

My question is, can I bypass this config entirely? I'd rather not be dependent on several ettings files and keeping them in sync.

更新这段代码就成功了.

string address = "http://myservice.com/soap.svc";
Binding binding = new System.ServiceModel.BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress(address);
client = new MyServiceClient(binding, endpointAddress);

感谢您的投入!

推荐答案

当然 - 您可以在代码中完成所有配置.

Sure - you can do all configuration in code.

Uri tcpBaseAddress = new Uri("net.tcp://localhost:8000/");

ServiceHost host = new ServiceHost(typeof(MyService),tcpBaseAddress);

Binding tcpBinding = new NetTcpBinding( );

//Use base address as address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,"");
//Add relative address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,"MyService");
//Ignore base address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,
   "net.tcp://localhost:8001/MyService");

host.Open( );

http://en.csharp-online.net/WCF_Essentials%E2%80%94Programmatic_Endpoint_Configuration

这篇关于WCF - 在没有 app.config 的情况下使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆