在调用 WCF 服务器的 SQL 中创建 DLL 错误:找不到引用协定的默认终结点元素

本文关键字:引用 找不到 默认 结点 元素 错误 服务器 WCF 调用 SQL DLL | 更新日期: 2023-09-27 18:35:45

我正在寻找 2 小时的解决方案,所以我放弃并在这里发布。

我创建了一个 C# 3.5 DLL。它的目标很容易:

public static string CallWsMethodClient(string sXMLSettings, string sXMLIn)
    {
        try
        {
            WS_Generic.ServiceClient serv = new WS_Generic.ServiceClient();
            return serv.CallWsMethod(sXMLSettings, sXMLIn);
        }
        catch (Exception e)
        {
            XElement xRootNode = new XElement("ALL_XML_OUT");
            xRootNode.Add(new XElement("DLL_ERROR_MESS", e.GetType().Name + " - " + e.Message));
            xRootNode.Add(new XElement("DLL_ERROR_STACKTRACE", e.StackTrace));
            xRootNode.Add(new XElement("DLL_ERROR_INNER", e.InnerException));
            return xRootNode.ToString();
        }
    }

我有一个对网络服务(WS_Generic.ServiceClient)的服务引用。

我的目标是将此 dll 作为程序集导入到 SQL Server 2008R2 中,并从 SQL 调用该方法以调用 Web 服务。

我用这个命令导入DLL:

create assembly [blabla]

来自 'xxxx''blabla.dll'permission_set = 不安全

我使用 :

create function CallWsMethodClient(@sXMLSettings nvarchar(max), @sXMLIn nvarchar(max))
      returns nvarchar(max) external name blabla.[WCF_SQL.WcfClient].CallWsMethodClient

当我执行我的存储过程时...多田!

<ALL_XML_OUT>
  <DLL_ERROR_MESS>InvalidOperationException - Could not find default endpoint element that references contract 'WS_Generic.IService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.</DLL_ERROR_MESS>
  <DLL_ERROR_STACKTRACE>   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
   at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
   at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   at System.ServiceModel.ClientBase`1..ctor()
   at WCF_SQL.WS_Generic.ServiceClient..ctor()
   at WCF_SQL.WcfClient.CallWsMethodClient(String sXMLSettings, String sXMLIn)</DLL_ERROR_STACKTRACE>
  <DLL_ERROR_INNER />
</ALL_XML_OUT>

我只想死...有人有想法吗?

当然,我的dll的配置文件是name_of_dll.dll.config。

dll 可能在内存中,所以我必须在 dll 中编码我的端点?问题是每次 Web 服务的 url 更改时我都必须重新编译它。

提前致谢

在调用 WCF 服务器的 SQL 中创建 DLL 错误:找不到引用协定的默认终结点元素

您正在编写以 dB 为单位的代码。

为什么不将终结点 URL 作为存储在 dB 中的参数传入。

好的,对于解决方案,我遵循了本·罗宾逊的方式。

此 DLL 的目标永远不会更改,或者只会更改几次。

所以我在代码中放置绑定:

        [...]    
        serv = new WS_Generic.ServiceClient(ConfigureBinding(), ConfigureEndPointAddress());
        [...]

        private static EndpointAddress ConfigureEndPointAddress()
        {
            EndpointAddress endpointAddress = new EndpointAddress("xxx");
            return endpointAddress;
        }
        private static BasicHttpBinding ConfigureBinding()
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            binding.AllowCookies = false;
            binding.BypassProxyOnLocal = false;
            binding.CloseTimeout = TimeSpan.Parse("00:01:00");
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.MaxBufferPoolSize = 524288;
            binding.MaxBufferSize = 5242880;
            binding.MaxReceivedMessageSize = 5242880;
            binding.MessageEncoding = WSMessageEncoding.Text;
            binding.Name = "BasicHttpBinding_IService";
            binding.OpenTimeout = TimeSpan.Parse("00:01:00");
            binding.ReceiveTimeout = TimeSpan.Parse("00:10:00");
            binding.SendTimeout = TimeSpan.Parse("00:01:00"); ;
            binding.TextEncoding = Encoding.UTF8;
            binding.TransferMode = TransferMode.Buffered;
            binding.UseDefaultWebProxy = true;
            return binding;
        }

它现在有效!只剩下一个问题:当我想更改目标时,我必须重新编译dll!

感谢您的所有建议:)