0

我正在寻找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();
        }
    }

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

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

我使用以下命令导入 DLL:

create assembly [blabla]

来自 'xxxx\blabla.dll',权限设置 = 不安全

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

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

提前致谢

4

2 回答 2

0

好的,对于解决方案,我遵循了 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!

感谢您的所有建议:)

于 2013-10-18T10:54:04.133 回答
0

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

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

于 2013-10-17T17:42:33.457 回答