Restful wcf服务图片上传

时间:2011-08-05 00:15:27

标签: c# wcf rest

休息Wcf Serivce接受图片上传。 它接受图像为base64string。 我创建了一个简单的aspx页面来上传图像。 但是我遇到了很多错误。 “有时香奈儿工厂不可用” “没有端点监听”的错误。 这是我的web.config文件。我不明白我在做什么错。 任何帮助将不胜感激。 目前,服务和客户端位于我的本地系统上。

客户端Web.config文件

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="WebHttpBinding_Service">
          <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
            messageVersion="Soap12" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </textMessageEncoding>
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="" binding="customBinding" bindingConfiguration="WebHttpBinding_Service"
        contract="ServiceReference1.Service" name="WebHttpBinding_Service" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

REST wcf Service Web.config

<system.serviceModel>
        <services>
            <service behaviorConfiguration="ServiceBehavior1" name="Service">
                <endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="REST">
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="REST">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior1">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

1 个答案:

答案 0 :(得分:0)

客户端和服务器端点配置不匹配。在服务上,您有一个带有“webHttpBinding”的端点和一个包含<webHttp/>行为的行为配置。在客户端上,您有一个自定义绑定,它不等同于webHttpBinding,并且没有行为。

问题似乎是REST端点不公开元数据,因此“添加服务引用”对它们不起作用。尝试将合同和绑定配置复制到客户端,或者如果它只是一个简单的“上传”服务,您可以使用比WCF更简单的东西,例如WebClient类。