سؤال

أقوم بتشغيل خدمة بسيطة على الخادم الخاص بي باستخدام WCF؛تتم استضافة الخدمة في WebDev.WebServer.exe (محلي).

عندما أتصل بالخدمة المحلية أحصل على الاستثناء التالي:

استثناء غير معالج:System.ServiceModel.Security.SecurityNegotiationException:لا يمكن فتح القناة الآمنة بسبب فشل المفاوضات الأمنية مع نقطة النهاية البعيدة.قد يكون هذا بسبب غياب EndpointIdentity أو تحديده بشكل غير صحيح في EndpointAddress المستخدم لإنشاء القناة.الرجاء التحقق من أن EndpointIdentity المحدد أو الضمني بواسطة EndpointAddress يحدد بشكل صحيح نقطة النهاية البعيدة.---> System.ServiceModel.FaultException:الرسالة مع الإجراء 'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issueلا يمكن معالجتها في جهاز الاستقبال ، بسبب عدم تطابق العقد في EndpointDispatcher.قد يكون هذا بسبب عدم تطابق العقد (الإجراءات غير المتطابقة بين المرسل والمستقبل) أو عدم تطابق الربط/الأمان بين المرسل والمستقبل.تأكد من أن المرسل والمتلقي لديهم نفس العقد ونفس الالتزام (بما في ذلك متطلبات الأمان، على سبيل المثال.الرسالة، النقل، لا شيء).

إليك ملفي app.config الخاصين بي من العميل والخادم.لقد قمت بإنشاء app.config من العميل باستخدام أداة svcutil لذا يجب أن يكون صحيحًا:

عميل

<client>
    <endpoint address="http://localhost:1634/UsuarioContexto.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IUsuarioContexto"

        contract="CarWin.ServiceContracts.Interfaces.IUsuarioContexto" name="LOCAL_WSHttpBinding_IUsuarioContexto">

        <identity><dns value="localhost" /></identity>

    </endpoint>

</client>

<binding name="WSHttpBinding_IUsuarioContexto" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />

    <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />

    <security mode="Message">

        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />

        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />

    </security>

</binding>

الخادم

<services>
    <service behaviorConfiguration="UsuarioContextoBehavior" name="UserContext.Host.UsuarioContexto">

        <endpoint address="" binding="wsHttpBinding" bindingNamespace="http://CarWin" bindingConfiguration="wsHttpBinding_IUsuarioContexto"

                  contract="CarWin.ServiceContracts.Interfaces.IUsuarioContexto">

            <identity>

                <dns value="localhost" />

            </identity>

        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

    </service>

</services>


<bindings>

    <wsHttpBinding>

        <binding name="wsHttpBinding_IUsuarioContexto" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

            <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" />

            <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />

            <security mode="None">

                <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />

                <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />

            </security>

        </binding>

    </wsHttpBinding>

</bindings>

<behaviors>

    <serviceBehaviors>

        <behavior name="UsuarioContextoBehavior">

            <serviceMetadata httpGetEnabled="true" />

            <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

    </serviceBehaviors>

</behaviors>
هل كانت مفيدة؟

المحلول

كانت المشكلة في الخادم، قمت بوضع الوضع = "الرسالة" ويعمل بشكل جيد.شكرًا.

<security mode="None">  

<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />  

<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />  

</security> 

نصائح أخرى

يعد WCF قويًا جدًا، ولكنه يمكن أن يكون كابوسًا للتكوين.فيما يلي بعض الخيوط المحتملة:

  • قم بتشغيل سجلات تتبع WCF، وأعد تشغيل السيناريو ثم تحقق من السجلات باستخدام SvcTraceViewer.exe
  • اكتشف إلى أي مدى تصل الرسائل...
    • أي.هل يقوم العميل بتكوين الطلب وإرساله إلى الخادم الذي يرفضه (أي؟في طبقات WCF السفلية قبل الضغط على رمز الخدمة الخاص بك)؛
    • أم أن الطلب يتوقف في مساراته قبل ذلك..العميل لم يرسل الطلب أبدًا
  • http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue هي رسالة متعلقة برمز WS-Trust، لذلك سيكون هناك شيء ما يحدث في المصادقة
    • يشير الخطأ إلى وجود عدم تطابق في التكوين، ولكن استخدام SvcUtil يجب أن يجعلهم مصطفين كما قلت
  • ربط العميل لديه الخادم في "http://localhost:1634/UsuarioContexto.svc"
    • لا أرى هذا المنفذ المحدد في تكوين الخدمة ...هل الخدمة تستمع على هذا المنفذ؟
    • إذا قمت بفتح متصفح ووجهته إلى عنوان URL هذا، فهل تحصل على صفحة خدمة افتراضية؟
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top