在这里,我展示了通过WCF功能上传图像的全部功能。
每当我拨打以下服务时,我的请求都会变坏。请找出我犯错的地方。
我的wcf服务:
http://XXX.XXX.X.XX:/RestServiceImpl.svc/send?canvasbyte=[B@40fa5860&EmployeeID=1
我的服务界面:
[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>
答案 0 :(得分:1)
您可能需要考虑将图片作为base64
编码string
或stream
传递。
以下链接概述了选项:
How to return a Base64 encoded byte array from a WCF REST service using JSON?