c# - Error while sending file to WCF: The request failed with HTTP status 400: Bad Request -


i trying upload file using wcf service. getting the request failed http status 400: bad request at:

ds = wcfspend.registersupplier("blah", new spendwcfref.filedata  {      filename = myfile.filename.tostring(),      bufferdata = file,      fileposition = 1 }); 

wcf:

public dataset registersupplier(string supplierid, filedata file) {     dataset ds = new dataset();     return ds; }  [servicecontract] public interface ispend {      [operationcontract]     dataset executeprocedure(string procedurename, string[] paramsname, string[] paramsvalue, int num);      [operationcontract]     dataset registersupplier(string supplierid, filedata file);      //[operationcontract]     //bool uploadfiledata(filedata filedata); }  [datacontract] public class filedata {     [datamember]     public string filename { get; set; }      [datamember]     public byte[] bufferdata { get; set; }      [datamember]     public int fileposition { get; set; } } 

application:

ds = wcfspend.registersupplier("blah", new spendwcfref.filedata {      filename = myfile.filename.tostring(),      bufferdata = file, fileposition = 1 }); 

apllication config file:

<system.servicemodel>     <bindings>         <basichttpbinding>             <binding name="basichttpbinding_ispend"                  closetimeout="00:01:00"                      opentimeout="00:01:00"                  receivetimeout="00:10:00"                  sendtimeout="00:01:00"                  allowcookies="false"                  bypassproxyonlocal="false"                 hostnamecomparisonmode="strongwildcard"                 maxbuffersize="2147483647"                  maxbufferpoolsize="2147483647"                  maxreceivedmessagesize="2147483647"                  messageencoding="text"                  textencoding="utf-8"                  transfermode="buffered"                  usedefaultwebproxy="true">                 <readerquotas maxdepth="2147483647"                     maxstringcontentlength="2147483647"                     maxarraylength="2147483647"                     maxbytesperread="2147483647"                      maxnametablecharcount="2147483647" />                 <security mode="none">                     <transport clientcredentialtype="none"                          proxycredentialtype="none"                          realm="" />                     <message clientcredentialtype="username"                          algorithmsuite="default" />                 </security>             </binding>         </basichttpbinding>     </bindings>     <client/> </system.servicemodel> 

wcf web config:

<system.servicemodel>     <bindings>         <basichttpbinding>             <binding name="mybindingforbigarrays"                 opentimeout="00:10:00"                  closetimeout="00:10:00"                  receivetimeout="00:10:00"                  sendtimeout="00:10:00"                  maxreceivedmessagesize="2147483647"                 maxbufferpoolsize="2147483647"                  maxbuffersize="2147483647">                 <readerquotas maxdepth="64"                     maxstringcontentlength="2147483647"                     maxarraylength="2147483647"                     maxbytesperread="4096"                     maxnametablecharcount="16384"/>             </binding>         </basichttpbinding>     </bindings>     <behaviors>         <servicebehaviors>             <behavior>                 <!-- avoid disclosing metadata information, set value below false , remove metadata endpoint above before deployment -->                 <servicemetadata httpgetenabled="true"/>                 <!-- receive exception details in faults debugging purposes, set value below true.  set false before deployment avoid disclosing exception information -->                 <servicedebug includeexceptiondetailinfaults="false"/>             </behavior>         </servicebehaviors>     </behaviors>     <servicehostingenvironment multiplesitebindingsenabled="true" /> </system.servicemodel>  

there few things resulting in error seeing. first thing recommend assign binding configurations created explicitly defined endpoint. this:

<!-- goes in <system.servicemodel> section --> <services>   <service name="myservice">     <endpoint address=""                binding="wshttpbinding"               bindingconfiguration="mybindingforbigarrays"               contract="<namespace>.ispend" />   </service> </services> 

the above configuration service. make sure qualify contract name namespace, , service name needs same name in markup of .svc file.

you similar client, except <client> tag, rather <service>.

if don't specify binding configuration use in endpoint, wcf use default (lower) values binding type selected. alternative make binding configuration default kind of binding, omitting name attribute.

if doesn't solve issue, can try adjusting maxrequestlength value <httpruntime> element in <system.web>. <system.web> child of <configuration>:

<system.web>     <httpruntime maxrequestlength="2147483647" /> </system.web> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -