【问题标题】:Restful wcf Service image uploadRestful wcf 服务图片上传
【发布时间】:2011-08-05 00:15:27
【问题描述】:

Rest Wcf 服务接受图片上传。 它接受图像作为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 服务 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>

【问题讨论】:

    标签: c# wcf rest


    【解决方案1】:

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

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

    【讨论】:

    • 我只是想将图像作为base64String上传到WCF服务以进行测试,是否有可用的REST客户端可以测试上述场景。
    • 您也可以使用 WCF 客户端,但您必须手动更新生成的配置和合同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 2015-05-13
    • 1970-01-01
    相关资源
    最近更新 更多