当我尝试将图像作为byte[]发送时,WCF服务请求错误
本文关键字:WCF 错误 请求 服务 图像 byte | 更新日期: 2023-09-27 18:10:08
这里我展示了通过WCF功能上传图片的全部功能。
每当我调用下面的服务,我得到不好的请求。请找出我写错的地方。
我的wcf服务:
http://XXX.XXX.X.XX/RestServiceImpl.svc/发送? canvasbyte = [B@40fa5860& EmployeeID = 1
My Service Interface:
[OperationContract]
[WebGet(
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/send?canvasbyte={imgbyte}&EmployeeID={EmployeeID}")]
string sendresponse(Byte[] imgbyte, string EmployeeID);
我的SVC public string sendresponse(Byte[] imgbyte, string EmployeeID)
{
db.GetExcuteNonQuery("update emp_tb_eob_Employee set Signature='" + imgbyte + "' where EmployeeID=" + EmployeeID);
return "Success";
}
Webconfig文件 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<connectionStrings>
<add name="Databaseconnection" connectionString="Database=Test_Exenta;Server=192.168.1.XX;User ID=XXXXX;Password=XXXXX" providerName="System.Data.SqlClient" /></connectionStrings>
<system.web>
<httpRuntime maxUrlLength="2097151" maxQueryStringLength="2097151" maxRequestLength="2097151" requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://192.168.1.11:5252" />
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web" bindingConfiguration="RESTServiceBinding">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- 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>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="RESTServiceBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" transferMode="Streamed" sendTimeout="00:01:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
<defaultDocument>
<files>
<remove value="Default.htm" />
<remove value="Default.asp" />
<remove value="index.html" />
<remove value="index.htm" />
<remove value="iisstart.htm" />
<remove value="default.aspx" />
<add value="RestServiceImpl.svc" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
您可以考虑将图像传递为base64
编码的string
或stream
。
下面的链接很好地概述了这些选项:
如何使用JSON从WCF REST服务返回Base64编码的字节数组?