[Webservice / C#] Domyślny Binding

0

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:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data hostNameComparisonMode=&quot;StrongWildcard&quot; maxBufferSize=&quot;65536&quot; messageEncoding=&quot;Text&quot; name=&quot;WebsitesBinding&quot; textEncoding=&quot;utf-8&quot; transferMode=&quot;Buffered&quot;&gt;&lt;readerQuotas maxArrayLength=&quot;16384&quot; maxBytesPerRead=&quot;4096&quot; maxDepth=&quot;32&quot; maxNameTableCharCount=&quot;16384&quot; maxStringContentLength=&quot;8192&quot; /&gt;&lt;security mode=&quot;None&quot;&gt;&lt;message algorithmSuite=&quot;Default&quot; clientCredentialType=&quot;UserName&quot; /&gt;&lt;transport clientCredentialType=&quot;None&quot; proxyCredentialType=&quot;None&quot; realm=&quot;&quot; /&gt;&lt;/security&gt;&lt;/Data&gt;" bindingType="basicHttpBinding" name="WebsitesBinding" />
    <binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data hostNameComparisonMode=&quot;StrongWildcard&quot; maxBufferSize=&quot;65536&quot; messageEncoding=&quot;Text&quot; name=&quot;UsersBinding&quot; textEncoding=&quot;utf-8&quot; transferMode=&quot;Buffered&quot;&gt;&lt;readerQuotas maxArrayLength=&quot;16384&quot; maxBytesPerRead=&quot;4096&quot; maxDepth=&quot;32&quot; maxNameTableCharCount=&quot;16384&quot; maxStringContentLength=&quot;8192&quot; /&gt;&lt;security mode=&quot;None&quot;&gt;&lt;message algorithmSuite=&quot;Default&quot; clientCredentialType=&quot;UserName&quot; /&gt;&lt;transport clientCredentialType=&quot;None&quot; proxyCredentialType=&quot;None&quot; realm=&quot;&quot; /&gt;&lt;/security&gt;&lt;/Data&gt;" bindingType="basicHttpBinding" name="UsersBinding" />
    <binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data hostNameComparisonMode=&quot;StrongWildcard&quot; maxBufferSize=&quot;65536&quot; messageEncoding=&quot;Text&quot; name=&quot;FormsBinding&quot; textEncoding=&quot;utf-8&quot; transferMode=&quot;Buffered&quot;&gt;&lt;readerQuotas maxArrayLength=&quot;16384&quot; maxBytesPerRead=&quot;4096&quot; maxDepth=&quot;32&quot; maxNameTableCharCount=&quot;16384&quot; maxStringContentLength=&quot;8192&quot; /&gt;&lt;security mode=&quot;None&quot;&gt;&lt;message algorithmSuite=&quot;Default&quot; clientCredentialType=&quot;UserName&quot; /&gt;&lt;transport clientCredentialType=&quot;None&quot; proxyCredentialType=&quot;None&quot; realm=&quot;&quot; /&gt;&lt;/security&gt;&lt;/Data&gt;" bindingType="basicHttpBinding" name="FormsBinding" />
  </bindings>
  <endpoints>
    <endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/WebsitesPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;WebsitesBinding&quot; contract=&quot;ServiceReference1.WebsitesInterface&quot; name=&quot;WebsitesPort&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/WebsitesPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;WebsitesBinding&quot; contract=&quot;ServiceReference1.WebsitesInterface&quot; name=&quot;WebsitesPort&quot; /&gt;" contractName="ServiceReference1.WebsitesInterface" name="WebsitesPort" />
    <endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/UsersPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;UsersBinding&quot; contract=&quot;ServiceReference1.UsersInterface&quot; name=&quot;UsersPort&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/UsersPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;UsersBinding&quot; contract=&quot;ServiceReference1.UsersInterface&quot; name=&quot;UsersPort&quot; /&gt;" contractName="ServiceReference1.UsersInterface" name="UsersPort" />
    <endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/FormsPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;FormsBinding&quot; contract=&quot;ServiceReference1.FormsPortType&quot; name=&quot;FormsPort&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/FormsPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;FormsBinding&quot; contract=&quot;ServiceReference1.FormsPortType&quot; name=&quot;FormsPort&quot; /&gt;" contractName="ServiceReference1.FormsPortType" name="FormsPort" />
  </endpoints>
</configurationSnapshot>

Dla większej czytelności wyszczegolniony fragment pliku konfiguracyjnego:

    <endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/FormsPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;FormsBinding&quot; contract=&quot;ServiceReference1.FormsPortType&quot; name=&quot;FormsPort&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://localhost/mvc/FormsPort.php&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;FormsBinding&quot; contract=&quot;ServiceReference1.FormsPortType&quot; name=&quot;FormsPort&quot; /&gt;" 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.

0

Wielkie dzięki, Twój post był dla mnie bardzo pomocny.

pozdrawiam

1 użytkowników online, w tym zalogowanych: 0, gości: 1