我在2小時內尋找解決方案,因此我放棄並在此處張貼。在SQL中調用WCF服務器的DLL錯誤:找不到引用合同的默認端點元素
我有一個C#3.5 DLL創建。它的目標是soooooo方便:
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中的方法來調用websevice。
我導入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
當我執行我的庫存程序... 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改變。
在此先感謝,
「我的DLL的配置文件是name_of_dll.dll.config」 - 你一定要明白,DLL的不要」使用配置文件,對不對?除非你在DLL中編寫了一些自定義的東西。 – Tim
當你添加一個服務引用到你的dll時,Visual Studio創建一個dll的配置文件來配置端點。它的名字是VS中的app.config,編譯後是name_of_the_dll.dll.config。 – BaptX
是的。並且,當您在Visual Studio中創建類庫(DLL)項目時,它也包含一個app.config文件 - 並不意味着該DLL實際使用它。我沒有在SQL Server中運行託管代碼,所以它可能在這種情況下會有所不同,但我廣泛使用DLL和WCF,並且我一直必須將服務模型部分放入消費應用程序的配置文件中。至少按我的經驗,DLL總是使用調用應用程序的配置文件。 – Tim