2

ASP.net 4.0Webサイト内にあるWCFWebサービスを呼び出すC#4.0コンソールアプリがあります。Webサービスが呼び出されると、次のエラーが発生します。

The formatter threw an exception while trying to deserialize the message: 
Error in deserializing body of request message for operation 'AddArticle'. 
The maximum string content length quota (8192) has been exceeded while 
reading XML data. This quota may be increased by changing the 
MaxStringContentLength property on the XmlDictionaryReaderQuotas object 
used when creating the XML reader. 
Line 60, position 267.

したがって、周りを見回すと、構成ファイル内のmaxStringContentLengthプロパティとmaxReceivedMessageSizeプロパティを多数に増やす必要があるようです。私はこれを行いましたが、それでもエラーを受け取ります。

私のコンソールアプリからの設定は次のとおりです。

    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IXXXInterface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                    <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://axa-ppp/webservices/xxxinterface.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IXXXInterface" contract="XXX_YYYY_Interface.IXXXInterface" name="BasicHttpBinding_IXXXInterface"/>
    </client>

Webサイトの構成は次のとおりです。

      <binding name="BasicHttpBinding_IXXXInterface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          <security mode="None">
              <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
              <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
      </binding>

    <endpoint address="http://xxx-ppp/webservices/xxxinterface.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IXXXInterface" contract="XXX_YYYY_Interface.IXXXInterface" name="BasicHttpBinding_IXXXInterface"/>

編集:

これはウェブサイト上のクラスファイルです:

public class XXXInterface : IXXXInterface
{

public bool AddArticle(string Title, string ArticleXml)
{
    ContentData article = new ContentData();
    article.Title = Title;
    article.Html = ArticleXml;
    article.FolderId = 320;

    ContentData newArticle = contentMgr.Add(article);

    if (newArticle == null)
    {
        return false;
    }
    else
    {
        return true;
    }        
}
}
4

1 に答える 1

0

問題が見つかりました!:D

問題は にありIdBookIssuerIssuedTokenBinding.CreateBindingElements()ます。

私はオーバーライドし、ベースを呼び出しませんでした:

public override BindingElementCollection CreateBindingElements()
{
    BindingElementCollection elements = new BindingElementCollection();

    elements.Add(this.security);
    elements.Add(this.transport);

    return elements;
}

今私はこれをやっています:

public override BindingElementCollection CreateBindingElements()
{
    BindingElementCollection elements = base.CreateBindingElements();

    var securityBindingElement = elements.Find<SecurityBindingElement>();
    elements.Remove(securityBindingElement);
    elements.Add(this.security);

    var transportBindingElement = elements.Find<HttpTransportBindingElement>();
    elements.Remove(transportBindingElement);
    elements.Add(this.transport);

    return elements;
}

そして、それは魅力のように機能します!

base を呼び出す必要がある理由を説明できません。誰かがコメントで説明できれば、それは素晴らしいことです!

https://stackoverflow.com/a/19574170/4339857

于 2014-12-09T06:25:40.560 に答える