繁体   English   中英

在 SQL 中创建一个调用 WCF 服务器的 DLL 错误:找不到引用合同的默认端点元素

[英]Making a DLL in SQL which call WCF Server Error : Could not find default endpoint element that references contract

我正在寻找 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) 的服务引用。

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

我使用以下命令导入 DLL:

create assembly [blabla]

来自 'xxxx\\blabla.dll' with permission_set = unsafe

我使用以下方法创建存储过程:

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

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

<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更改时我都必须重新编译它。

提前致谢

您正在编写存在于 dB 中的代码。

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

好的,对于解决方案,我遵循了 Ben Robinson 的方法。

这个 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!

感谢您的所有建议:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM