سؤال

أنا أكتب تطبيق WCF/WPF صغير لتغيير حجم الصور ولكن WCF يمنحني الحزن عندما أحاول إرسال صورة بحجم 28K إلى خدمتي من العميل. تعمل الخدمة بشكل جيد عندما أرسلها صورًا أصغر. لقد افترضت على الفور أن هذه مشكلة تكوين وقد صمدت الويب بحثًا عن المنشورات المتعلقة بخاصية MaxArrayLength في تكوين الربط الخاص بي. لقد رفعت الحدود على هذه الإعدادات على كل من العميل والخادم إلى الحد الأقصى 2147483647 ولكن لا يزال يحصل على الخطأ التالي:

ألقى Formatter استثناء أثناء محاولته تخلص من الرسالة: كان هناك خطأ أثناء محاولة إلغاء تعديل المعلمة http://mywebsite.com/services/serviceContracts/2009/01:OriginalImage. كانت رسالة innerexception "كان هناك خطأ يفرز كائن النوع system.drawing.image. تم تجاوز حصة طول الصفيف القصوى (16384) أثناء قراءة بيانات XML. يمكن زيادة هذه الحصة عن طريق تغيير خاصية MaxArrayLength على كائن XmlDictionareReaderQuotas المستخدم عند إنشاء قارئ XML. ". يرجى الاطلاع على innerexception لمزيد من التفاصيل.

لقد جعلت موكلي وخادمي يهيئ نفس الشيء ويبدو أنهما يلي: الخادم:

<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="32"
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647"
                              maxBytesPerRead="2147483647"
                              maxNameTableCharCount="2147483647" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:900/mex/"/>
                    <add baseAddress="net.tcp://localhost:9000/" />
                </baseAddresses>
            </host>
            <endpoint binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
            <endpoint  address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
</system.serviceModel>

ويبدو أن تكوين العميل الخاص بي يشبه:

 <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="32" 
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647" 
                              maxBytesPerRead="2147483647" 
                              maxNameTableCharCount="2147483647" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost:9000/" binding="netTcpBinding"
            bindingConfiguration="NetTcpBinding_ImageResizerServiceContract"
            contract="ImageResizerService.ImageResizerServiceContract"
            name="NetTcpBinding_ImageResizerServiceContract">
            <identity>
                <userPrincipalName value="me@domain.com" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

يبدو أنه بغض النظر عن ما قمت بتعيين هذه القيم على ، ما زلت أحصل على خطأ في قول أن WCF لا يمكنه تسلسل ملفي لأن أكبر من 16384. أي أفكار؟

تحديث: تم تغيير عنوان البريد الإلكتروني في علامة userprincipalName لخصوصيتي

هل كانت مفيدة؟

المحلول

سيئتي - لقد نسيت تطبيق تكوين الربط الخاص بي على نقطة النهاية الخاصة بي في التكوين من جانب الخادم. يجب أن يقرأ تكوين الخادم:

<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="2147483647"
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647"
                              maxBytesPerRead="2147483647"
                              maxNameTableCharCount="2147483647" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>

        </netTcpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:900/mex/"/>
                    <add baseAddress="net.tcp://localhost:9000/" />
                </baseAddresses>
            </host>
            <endpoint bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
            <endpoint  address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
</system.serviceModel>

لاحظ تم إضافة bindingConfiguration = "nettcpbinding_imageresizerServiceContract" إلى نقطة نهاية NETTCP. يعمل تطبيقي الآن مع صور أكبر. حلو.

نصائح أخرى

الرجاء إضافة <readerQuotas> في الربط.

هذه هي المشكلة الرئيسية أثناء تحميل وتنزيل البايت [] ، فقد حل مشكلتي.

<basicHttpBinding>
    <binding name="ServicesBinding" transferMode="Streamed" maxBufferSize="200000000"
        maxReceivedMessageSize="200000000" messageEncoding="Text"  
        receiveTimeout="00:10:00">
        <readerQuotas maxDepth="2147483647"
            maxStringContentLength="2147483647"
            maxArrayLength="2147483647"
            maxBytesPerRead="2147483647"
            maxNameTableCharCount="2147483647" />
    </binding>
</basicHttpBinding>

لقد استخدمت Microsoft SDK SVCConfigEditor. لديك هذا إذا كنت تستخدم Visual Studio (الذي يحتوي على نسخته الخاصة). إنه أيضًا تنزيل مجاني.

على محرك الأقراص الثابتة (تحقق من ملفات البرنامج وملفات البرنامج (x86)):

C: Program Files (x86) Microsoft SDKS Windows V7.0a bin netfx 4.0 أدوات svcconfigeditor.exe

C: Program Files Microsoft SDKS Windows V7.1 bin netfx 4.0 tools svcconfigeditor.exe

إذا كان لديك عمليات تثبيت متعددة من Microsoft SDK ، فإن الإصدار الذي تستخدمه سيعتمد على إصدار .NET الذي تقوم بتطويره تحت. ستلقي الأداة خطأ لإعلامك بأنك حاولت فتح ملف .dll ضمن الإصدار الخطأ.

لاستخدام الأداة ، أشر إلى ملف .dll الخاص بخدمتك واترك الأداة تقوم بالرفع الثقيل. هذا مفيد بشكل خاص إذا كان لديك خدمات تتحدث إلى الخدمات (خدمات الوكلاء). أيضًا ، ضع في اعتبارك أنك ربما تحتاج إلى إعداد تكوين لكل من عميلك (في التطبيق) وتكوينات الخادم (في WebService).

كنت أفتقد التكوين على نقطة النهاية من جانب الخادم. كان علي أن أفعل شيئين:

  1. ضع نقطة نهاية على تكوين من جانب الخادم الخاص بي ، تم تكوينه باستخدام SVCConfigEditor
  2. تذكر أن تضع MaxArrayLength في أداة SVCConfigEditor

أيضًا ، كان ASP.NET صعب الإرضاء بشأن هذه القيمة ، لذلك يمكنك محاولة تبسيط ربط التكوين الخاص بك وإيقاف تشغيله:

  <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />

إنه يعمل ، والذي كان يظهر سابقًا مرجعًا لـ net.tcp: //myservice.com/ac_service.svc/mex عند تصفح خدمة WCF ولكن الآن هوhttp://myservice.com/ac_service.svc؟wsdl

هل ستعمل في المستقبل أيضًا ، دون أي مشكلة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top