WCF Web服务绑定配置未被应用

4
我有一个名为“Palladium”的WCF Web服务,它是在VS2008解决方案中作为项目创建的。
我有一个ASP.Net Web应用程序,在名为“Palladium.svc”的页面上托管此服务。
当我向Web服务提交表单数据时,我的服务会接收到这些数据并可以使用它们。
现在我正在将图像发布到服务中,而发布大小超过了WCF的默认maxReceivedMessageSize属性。为了解决这个问题,我在ASP.Net Web应用程序的web.config文件上的终结点中添加了绑定配置。
我的问题是绑定配置似乎没有应用。该服务来自iPhone应用程序进行发布,当发布大小小于65k时,服务正常工作。一旦发布大小超过此限制,我就会收到400(错误请求)错误。为了测试目的,我在ASP.Net Web应用程序中创建了一个test.aspx文件,该文件发布了一些表单值和一个图像到Web服务。同样,当发布大小小于默认的65k大小时,服务正常工作。超过65k,我就会得到一个400错误。
测试页面发布到与以下URITemplate匹配的URL:/job-photo/{photoId}/{palladiumId}/{jobId} 如果有人能帮助我调试此问题,将不胜感激。 测试页面标记:
        <html xmlns="http://www.w3.org/1999/xhtml" >
        <head runat="server">
            <title></title>
        </head>
        <body>
            <form id="form1" action="http://localhost/cds/resources/services/palladium.svc/job-photo/1/235DE168-5D1C-46A4-89F2-FD17C6B9F415/567" method="post" enctype="multipart/form-data">
            <div>
                <input type="text" name="user" value="joe bloggs" />

                <input type="file" name="photo" />
                <input type="submit" name="btnsubmit" value="submit" />
            </div>
            </form>
        </body>
        </html>

web.config 中的服务信息:

     <system.serviceModel>
       <bindings>
         <wsHttpBinding>
           <binding name="large_message_binding" maxBufferPoolSize="5242880" maxReceivedMessageSize="5242880">
             <readerQuotas maxStringContentLength="5242880" maxArrayLength="5242880" maxBytesPerRead="5242880" />
           </binding>
         </wsHttpBinding>
       </bindings>

       <behaviors>
       <serviceBehaviors>
        <behavior name="CDS.UI.Resources.Services.PalladiumBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
       </serviceBehaviors>
      </behaviors>

      <services>
       <service behaviorConfiguration="CDS.UI.Resources.Services.PalladiumBehavior"
        name="CDS.UI.Resources.Services.Palladium">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="large_message_binding" contract="CDS.PalladiumService.IPalladium">

         <identity>
          <dns value="localhost" />
         </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       </service>
      </services>

     </system.serviceModel>

Palladium.svc 的标记语言

    <%@ ServiceHost Language="C#" Debug="true" Service="CDS.PalladiumService.Palladium" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
1个回答

4

我的理解是

Service="CDS.PalladiumService.Palladium"

应该引用底层类型。

同样需要从这里引用name属性:

<service behaviorConfiguration="CDS.UI.Resources.Services.PalladiumBehavior"
    name="CDS.UI.Resources.Services.Palladium">

如果您将它们分配给基础服务类的实际类型,是否解决了您的问题?

感谢建议 Leigh - "Palladium" 实际上是服务类的类型。只要帖子大小不超过65k,该服务就可以完美运行。 - Nick W
嗨,尼克,即使你从web.config中删除了服务配置,该服务仍将正常工作。我的观点是,如果这两个元素不相同,那么我认为配置与服务的匹配不会发生。 - Leigh S
谢谢Leigh,对配置的更改有所帮助。在进行更改后,配置似乎被服务使用了 - 尽管现在我遇到了完全不同的错误。我在这里创建了一个新问题,描述了我现在遇到的问题 - 也许你能为我提供一些指导! - Nick W
1
真希望我三天前就能找到这篇文章,那时候就解决了我的问题。我想补充一下,它们显然也是区分大小写的。所以要小心! - MisterIsaak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接