Restful wcf服务图片上传
问题描述:
休息Wcf服务接受图片上传。 它接受图像作为base64string。 我已经创建了一个简单的aspx页面来上传图片。 但我收到了很多错误。 “有一段时间Chanel工厂不可用” “没有端点收听”类错误。 这里是我的web.config文件。我不明白我在做什么错误。 任何帮助将不胜感激。 当前服务和客户端位于我的本地系统上。Restful wcf服务图片上传
客户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>
答
客户端和服务器端点配置不匹配。在服务上,您有一个带有“webHttpBinding”的端点,并且该行为配置包含<webHttp/>
行为。在客户端上,您有一个自定义绑定,它不等同于webHttpBinding
,并且没有任何行为。
问题似乎是REST端点未公开元数据,因此“添加服务引用”对他们来说效果不佳。尝试将合同和绑定配置复制到客户端,或者如果它只是一个简单的“上传”服务,则可以使用比WCF更简单的内容,例如WebClient
类。
我只是想上传一个图像作为base64String WCF服务,以测试它,是否有任何REST客户端可用,我可以测试上述情况。 – Henry
您也可以使用WCF客户端,但您必须手动更新生成的配置和合同。 – carlosfigueira