0

我现在正在编写一个网络服务,用法如下:

我有一个作为 dll 的前端,这意味着我有一个带有 wpf 窗口的库项目。该库应从其他程序中调用。后端 WCF 服务托管在外部 IIS 上,前端通过引用 wcf 服务的 controller.dll 调用 Web 服务方法。

我在这里和谷歌已经阅读了几篇关于同样问题的帖子......但我无法修复它。

我有一个虚拟的 windows 窗体,它调用 frontend.dll。该项目得到了app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10: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="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://Hidden-ip/TicketReportService.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
          contract="ServiceReference.IService" name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>

我知道,如果我按照我在此处描述的方式进行操作,每个想要调用我的 frontend.dll 的程序都需要将绑定/端点配置放在他们自己的 app.config 中。这只是一个例子,后来我在我的 controller.dll 中以编程方式进行绑定/端点配置,所以我不需要配置文件......但那是另一个话题。

如果我调用我的方法,通过网络服务上传文件,我有两种情况:

如果文件 > 16kb 并且 <~30kb 我得到一个协议异常,那就是告诉我"MaxArrayLength" (16384) was exceeded.

如果我尝试上传大约 60kb 的文件,我也会收到协议异常,但仅包含以下信息:“remoteserver returned unexpected answer.(400) bad request.

如果您查看 app.config,maxarray 长度设置为 int32.max 值。此外,如果我检查调用该方法的对象的绑定,它会告诉我 maxarraylength 是从 app.config 中获取的......但我仍然收到错误消息。

我在这里做错了什么?那是客户端的问题,我不是吗?

在 IIS 上的服务 web.config 中,我得到以下信息:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="BackendService.Behavior" name="MyNamespaye.Service">
                <endpoint address="" binding="basicHttpBinding" contract="MyNamespaye.IService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="BackendService.Behavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
    <connectionStrings>
        <add name="CustomerEntities" connectionString="metadata=res://*/CustomerModel.csdl|res://*/CustomerModel.ssdl|res://*/CustomerModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=hidden-ip;User Id=root;database=fromcloud;password=hidden-pw;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />
        <add name="DocumentEntities" connectionString="metadata=res://*/DocumentModel.csdl|res://*/DocumentModel.ssdl|res://*/DocumentModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=hidden-ip;User Id=root;password=hidden-pw;Persist Security Info=True;database=fromcloud&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>
4

1 回答 1

0

...自己修好了。不知道它也必须在服务端配置!

新的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService" closeTimeout="00:10:00"
                    openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10: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="2147483647" maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="BackendService.Behavior" name="MyNamespace.Service">
              <host>
                  <baseAddresses>
                    <add baseAddress="http://localhost:1111/"/>
                  </baseAddresses>
            </host>
             <endpoint address="http://MyIP/TicketReportService.svc"
                  binding="basicHttpBinding" 
                  bindingConfiguration="BasicHttpBinding_IService"
                  contract="Mynamespace.BackendService.IService" 
                  name="ticketReport_endpoint" />

            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="BackendService.Behavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
    <connectionStrings>
        <add name="CustomerEntities" connectionString="metadata=res://*/CustomerModel.csdl|res://*/CustomerModel.ssdl|res://*/CustomerModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=fwefwef;User Id=root;database=fromcloud;password=fwefw;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />
        <add name="DocumentEntities" connectionString="metadata=res://*/DocumentModel.csdl|res://*/DocumentModel.ssdl|res://*/DocumentModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=fwefwef;User Id=root;password=fwef;Persist Security Info=True;database=fromcloud&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

...刚刚做了另一个谷歌搜索,发现了一个合适的 web.config 示例。无论如何,感谢任何阅读 OP 的人。

于 2013-06-05T07:36:34.857 回答