Restful wcf服务图像上传

本文关键字:图像 服务 wcf Restful | 更新日期: 2023-09-27 18:04:29

Rest Wcf服务接受图片上传。它接受图像为base64string。我已经创建了一个简单的aspx页面来上传图像。但是我得到了很多错误。"有时香奈儿工厂无法使用"倾听没有终点"之类的错误。这是我的网。配置文件。我不明白我犯了什么错误。任何帮助都将不胜感激。当前服务和客户端位于我的本地系统。

Web客户端。配置文件

<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>

Restful wcf服务图像上传

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

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