Witam.
Mam problem ze skonfigurowaniem klienta.
Jeśli usługa ma więcej niż jeden Binding, przy tworzeniu kolejnego dostaję komunikat:
Nie można znaleźć domyślnego elementu punktu końcowego odwołującego się do kontraktu „ServiceReference1.FormsPortType” w sekcji konfiguracji klienta ServiceModel. Może to być spowodowane tym, że nie znaleziono pliku konfiguracyjnego dla używanej aplikacji lub tym, że w elemencie klienta nie znaleziono elementu punktu końcowego pasującego do tego kontraktu.
Szczegóły:
System.Reflection.TargetInvocationException was unhandled
Message="Obiekt docelowy wywołania zgłosił wyjątek."
Source="mscorlib"
StackTrace:
w System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
w System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
w System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
w System.Activator.CreateInstance(Type type, Boolean nonPublic)
w System.Activator.CreateInstance(Type type)
w WideCMS.Modules.Add(String assemblyFile) w C:\htdocs\WideCMS\WideCMS\Modules.cs:wiersz 86
w WideCMS.Modules.LoadFrom(String path) w C:\htdocs\WideCMS\WideCMS\Modules.cs:wiersz 71
w WideCMS.Form1..ctor() w C:\htdocs\WideCMS\WideCMS\Form1.cs:wiersz 70
w WideCMS.Program.Main() w C:\htdocs\WideCMS\WideCMS\Program.cs:wiersz 18
w System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
w System.Threading.ThreadHelper.ThreadStart_Context(Object state)
w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
w System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidOperationException
Message="Nie można znaleźć domyślnego elementu punktu końcowego odwołującego się do kontraktu „ServiceReference1.FormsPortType” w sekcji konfiguracji klienta ServiceModel. Może to być spowodowane tym, że nie znaleziono pliku konfiguracyjnego dla używanej aplikacji lub tym, że w elemencie klienta nie znaleziono elementu punktu końcowego pasującego do tego kontraktu."
Source="System.ServiceModel"
StackTrace:
w System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
w System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
w System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
w System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
w System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
w System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
w System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
w System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
w System.ServiceModel.ClientBase`1..ctor()
w Forms.ServiceReference1.FormsPortTypeClient..ctor() w c:\htdocs\widecms\modules\forms\service references\servicereference1\reference.cs:wiersz 537
w Forms.FormsModule..ctor() w C:\htdocs\WideCMS\Modules\Forms\Forms.cs:wiersz 28
InnerException:
Klasa klienta tworzona jest w następujący sposób:
ServiceReference1.FormsPortTypeClient client = new ServiceReference1.FormsPortTypeClient();
Z informacji z msdn wiem, że powinienem podać nazwę punktu końcowego endpoint z pliku konfiguracyjnego, czyli powinno to wyglądać wg. mnie tak:
ServiceReference1.FormsPortTypeClient client = new ServiceReference1.FormsPortTypeClient("FormsPort");
Plik z konfiguracją wygląda następująco:
<?xml version="1.0" encoding="utf-8"?>
<configurationSnapshot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-microsoft-com:xml-wcfconfigurationsnapshot">
<behaviors />
<bindings>
<binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:<?xml version="1.0" encoding="utf-16"?><Data hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" messageEncoding="Text" name="WebsitesBinding" textEncoding="utf-8" transferMode="Buffered"><readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192" /><security mode="None"><message algorithmSuite="Default" clientCredentialType="UserName" /><transport clientCredentialType="None" proxyCredentialType="None" realm="" /></security></Data>" bindingType="basicHttpBinding" name="WebsitesBinding" />
<binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:<?xml version="1.0" encoding="utf-16"?><Data hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" messageEncoding="Text" name="UsersBinding" textEncoding="utf-8" transferMode="Buffered"><readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192" /><security mode="None"><message algorithmSuite="Default" clientCredentialType="UserName" /><transport clientCredentialType="None" proxyCredentialType="None" realm="" /></security></Data>" bindingType="basicHttpBinding" name="UsersBinding" />
<binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:<?xml version="1.0" encoding="utf-16"?><Data hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" messageEncoding="Text" name="FormsBinding" textEncoding="utf-8" transferMode="Buffered"><readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192" /><security mode="None"><message algorithmSuite="Default" clientCredentialType="UserName" /><transport clientCredentialType="None" proxyCredentialType="None" realm="" /></security></Data>" bindingType="basicHttpBinding" name="FormsBinding" />
</bindings>
<endpoints>
<endpoint normalizedDigest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/WebsitesPort.php" binding="basicHttpBinding" bindingConfiguration="WebsitesBinding" contract="ServiceReference1.WebsitesInterface" name="WebsitesPort" />" digest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/WebsitesPort.php" binding="basicHttpBinding" bindingConfiguration="WebsitesBinding" contract="ServiceReference1.WebsitesInterface" name="WebsitesPort" />" contractName="ServiceReference1.WebsitesInterface" name="WebsitesPort" />
<endpoint normalizedDigest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/UsersPort.php" binding="basicHttpBinding" bindingConfiguration="UsersBinding" contract="ServiceReference1.UsersInterface" name="UsersPort" />" digest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/UsersPort.php" binding="basicHttpBinding" bindingConfiguration="UsersBinding" contract="ServiceReference1.UsersInterface" name="UsersPort" />" contractName="ServiceReference1.UsersInterface" name="UsersPort" />
<endpoint normalizedDigest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/FormsPort.php" binding="basicHttpBinding" bindingConfiguration="FormsBinding" contract="ServiceReference1.FormsPortType" name="FormsPort" />" digest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/FormsPort.php" binding="basicHttpBinding" bindingConfiguration="FormsBinding" contract="ServiceReference1.FormsPortType" name="FormsPort" />" contractName="ServiceReference1.FormsPortType" name="FormsPort" />
</endpoints>
</configurationSnapshot>
Dla większej czytelności wyszczegolniony fragment pliku konfiguracyjnego:
<endpoint normalizedDigest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/FormsPort.php" binding="basicHttpBinding" bindingConfiguration="FormsBinding" contract="ServiceReference1.FormsPortType" name="FormsPort" />" digest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost/mvc/FormsPort.php" binding="basicHttpBinding" bindingConfiguration="FormsBinding" contract="ServiceReference1.FormsPortType" name="FormsPort" />" contractName="ServiceReference1.FormsPortType" name="FormsPort" />
Niestety w dalszym ciągu dostaję komunikat błędu... Będę wdzięczny za pomoc.
EDIT
Dokładniej mówiąc odkryłem, że główna konfiguracja app.config jest używana przez klasy (pluginy) korzystające z Webservice. Mimo, że pluginy te mają swoją konfigurację, z jakiś powodów brana jest pod uwagę tylko ta z aplikacji głównej (host). Jak to zmienić?
EDIT 2 :)
Problem rozwiązany poprzez ominięcie obsługi plików konfiguracyjnych. Dla ciekawskich, podaję rozwiązanie pod adresem: http://msdn.microsoft.com/en-us/library/ms574912.aspx.