0

Hi I'm trying to post a Uint8Array from angular javascript client to wcf service. The problem is that when the array arrives at the service it is null. On the client end I've tried changing the array to different types (int8, int16 etc..) and also not stringifying the data, but in all cases when it arrives at the service it is null. On the service side I've tried to change the BodyStyle of the interface from Wrapped to Bare, but got a 500 error. I've also made changes to web config parameters, but I think web config is ok, because the post is actually making it to the method.

Any ideas what could be the problem? ultimately I'm trying to post an image from webcam on ipad or laptop to wcf service for input into sql server. My code is below

Thanks

Pete

//ANGULAR post to WCF
   const data = new Uint8Array(8);
    data[0] = 26;
    let body:any = JSON.stringify(data);// body = '{"0":26,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0}'
    let headers = {'Access-Control-Allow-Credentials':'false',
    'Access-Control-Allow-Origin': '*', 
    'Access-Control-Allow-Methods': 'DELETE, POST, GET, OPTIONS, PUT', 
    'Access-Control-Allow-Headers': 'application/json',
    'Content-Type':'application/json'} 
    this.http.post(GlobalConstants.UploadServiceURL + "UploadPhotoDB", body, {'headers':headers}).subscribe(data => {
      console.log(data);// null
  })

WCF SERVICE
//Method
public byte[] UploadPhotoDB(byte[] input){//input is null
   return input;
}

//Interface
  [OperationContract(Name = "UploadPhotoDB")]
        [DataContractFormat]
        [WebInvoke(Method = "POST",
                  UriTemplate = "UploadPhotoDB/",
                  BodyStyle = WebMessageBodyStyle.Wrapped,
                  ResponseFormat = WebMessageFormat.Json,
                  RequestFormat = WebMessageFormat.Json
            ),
            ]
   byte[] UploadPhotoDB(byte[] input);

//Applicable parts of WebConfig

<service name="SARIService.ServiceUpload" behaviorConfiguration="ServiceBehavior">
        <endpoint address="" 
                  binding="webHttpBinding" 
                  bindingConfiguration="webHttpBindingConfig" 
                  contract="SARIService.IServiceUpload" 
                  behaviorConfiguration="web">
        </endpoint>
      </service>
<endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
<serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
   <bindings>
      <webHttpBinding>
        <binding
            maxBufferSize="999999" maxReceivedMessageSize="999999" />
        <binding name="webHttpBindingConfig"
                 maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Streamed" sendTimeout="00:05:00">
         <!-- <security mode="Transport"/>-->
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        </binding>
      </webHttpBinding>
    </bindings>
2
  • You can take a look at: stackoverflow.com/questions/46721952/… Commented Jun 24, 2021 at 8:39
  • I'm able to post a base64 string to the wcf service using code from here: stackoverflow.com/questions/52266300/… that converts ArrayBuffer to Base64 string, and then convert string to byte array on C# side, but the file is an image and it seems to be getting corrupted -- cant read it out of the database Commented Jun 24, 2021 at 16:04

1 Answer 1

0

On the angular javascript side I'm using ngx-webcam module to get the image. This has an imageAsBase64 property which stores the image as a base64 string. When I posted this string to the service and used FromBase64String on the c# wcf service to convert back to a byte array it worked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.