我收到参数无效错误。如何解决这个问题?
以下代码是服务器端
MemoryStream ms = new MemoryStream(ObjDt.ImgUpload);
ms.Write(ObjDt.ImgUpload, 0, ObjDt.ImgUpload.Length);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
image.Dispose();
image.Save(@"D:\Projects\WCF\WCF_ImageUpload\DamagedImages\" + strRandNo + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// image.Save(@"C:\DotNet\ImageUpload\DamagedImages\" + strRandNo + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
//return strRandNo.ToString();
string val = strRandNo.ToString();
IPAddress = "localhost:53865/WCF/Image" + val + ".jpg";
在这些代码中,我得到 Parameter is not valid error..这些代码的 Web 配置是
<bindings>
<basicHttpBinding>
<binding name="StreamedBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!-- <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicBinding1" contract="WCF_ImageUpload.IService1"></endpoint>-->
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="StreamedBinding" bindingName="ServiceBehavior"
contract="WCF_ImageUpload.IService1" />
</service>
</services>
我在 Windows 应用程序中使用了以下客户端应用程序。
Uri uri = new Uri("http://localhost:53865/Service1.svc/UploadDamagedImage");
Details ObjDt = new Details();
ObjDt.Name = "hi";
ObjDt.Email = "hi@gmail.com";
ObjDt.ContactNumber = "3698754215";
ObjDt.DeviceModel = "E23";
ObjDt.Problem = "Repair";
ObjDt.Besttimetocontact = "9am";
byte[] bytes = File.ReadAllBytes("D:/WCFImages/admin.png");
ObjDt.ImgUpload = bytes;
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Details));
// xmlserializer xser = new xmlserializer();
MemoryStream mem = new MemoryStream();
ser.WriteObject(mem, ObjDt);
string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
WebClient webClient = new WebClient();
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
webClient.Headers["Content-type"] = "application/json";
webClient.Encoding = Encoding.UTF8;
webClient.UploadStringAsync(uri, "POST", data);