0

我是 WCF 的新手,所以请多多包涵。

我有 StudentData.svc.vb,它实现了来自同一个 IStudentData.vb 的 2 个接口

这 2 个接口是 IStudentData 和 IHeartbeat Heartbeat 是一种单向操作合同 _

我正在使用 IIS 7.5 来托管这个 web.config 的服务

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings />
    <client />
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
        <add binding="basicHttpBinding" scheme="http" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</

创建服务引用后我的 app.config 是

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IStudentData" maxReceivedMessageSize="2147483647" />
                <binding name="BasicHttpBinding_IHeartbeat" maxReceivedMessageSize="2147483647" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://www.ortho-sync.com:8080/StudentData.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStudentData"
                contract="oStudentData.IStudentData" name="BasicHttpBinding_IStudentData" />
            <endpoint address="http://www.ortho-sync.com:8080/StudentData.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHeartbeat"
                contract="oStudentData.IHeartbeat" name="BasicHttpBinding_IHeartbeat" />
        </client>
    </system.serviceModel>
</configuration>

IStudentData 有一个带有字节数组数据成员的类,我用它来传输图像。如果我使用一个小文件,它会传输,如果我使用 1 兆图像,一切正常,我得到 (413) Request Entity Too Large

我一直在玩绑定和端点,直到我脸色发青,请任何人帮忙。

4

1 回答 1

1

您的服务正在获取绑定的默认值,因为您尚未指定自己的默认值basicHttpBinding或创建引用您自己的端点(在服务中)basicHttpBinding

name您可以通过省略属性使绑定配置成为该绑定的默认配置,如下所示:

<basicHttpBinding>
  <binding maxReceivedMessageSize="2147483647" />

bindingConfiguration或者,您可以显式创建端点并使用属性设置该端点的绑定配置:

<endpoint address=""
          binding="basicHttpBinding"  
          bindingConfiguration="BasicHttpBinding_IStudentData"
          contract="oStudentData.IStudentData" 
          name="BasicHttpBinding_IStudentData" />

第二个示例假定使用 a nameof定义的绑定配置BasicHttpBinding_IStudentData

您可以在服务配置文件中使用其中任何一个。

于 2013-10-23T02:39:29.630 回答