【问题标题】:WCF - use without app.configWCF - 在没有 app.config 的情况下使用
【发布时间】:2011-02-28 17:32:34
【问题描述】:

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

问题在于 Timer Service 无权访问从 Timer Service 的上下文设置 WCF 连接所需的 web.config 设置。

Could not find endpoint element with name endpointname' and contract 'servicecontractname' in the ServiceModel client configuration section

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

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

更新 这段代码就成功了。

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

感谢您的意见!

【问题讨论】:

标签: wcf sharepoint sharepoint-2007 config


【解决方案1】:

当然 - 您可以在代码中进行所有配置。

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

【讨论】:

    【解决方案2】:

    这是直接来自我们的SharePoint code for our PDF Converter product。它使用 HTTPBindings 并完全绕过配置文件。

        /// <summary>
        /// Configure the Bindings, endpoints and open the service using the specified address.
        /// </summary>
        /// <returns>An instance of the Web Service.</returns>
        public static DocumentConverterServiceClient OpenService(string address)
        {
            DocumentConverterServiceClient client = null;
    
            try
            {
                BasicHttpBinding binding = new BasicHttpBinding();
                // ** Use standard Windows Security.
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = 
                                                            HttpClientCredentialType.Windows;
                // ** Increase the Timeout to deal with (very) long running requests.
                binding.SendTimeout = TimeSpan.FromMinutes(30);
                binding.ReceiveTimeout = TimeSpan.FromMinutes(30);
                // ** Set the maximum document size to 40MB
                binding.MaxReceivedMessageSize = 50*1024*1024;
                binding.ReaderQuotas.MaxArrayLength = 50 * 1024 * 1024;
                binding.ReaderQuotas.MaxStringContentLength = 50 * 1024 * 1024;
    
                // ** Specify an identity (any identity) in order to get it past .net3.5 sp1
                EndpointIdentity epi = EndpointIdentity.CreateUpnIdentity("unknown");
                EndpointAddress epa = new EndpointAddress(new Uri(address), epi);
    
                client = new DocumentConverterServiceClient(binding, epa);
    
                client.Open();
    
                return client;
            }
            catch (Exception)
            {
                CloseService(client);
                throw;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 2012-05-07
      • 2015-01-23
      • 1970-01-01
      相关资源
      最近更新 更多