c#wcf service接受来自javascript的Int8Array作为参数

时间:2018-04-17 21:02:23

标签: javascript c# wcf

我在javascript中有一个Int8Array,我正在尝试传递给WCF服务。最终我将Int8Array转换为字节数组并将数据(照片)保存到数据库中。我遇到的问题是我无法让WCF服务接受Int8Array。 Int8Array是从javascript中的FileReader对象创建的。

创建Int8Array的Javascript代码

 var reader = new FileReader();
//display photo on page
reader.onload = function (e) {
dojo.byId('img1').src = reader.result;
var arrayBuffer = reader.result;
var u = new Int8Array(arrayBuffer);
FormSawpaDB.PhotoSave(u, lang.hitch(me.PhotoSaveConfirm));//me is the page
}

// Read in the image file as a data URL
reader.readAsArrayBuffer(f);

Javascript调用WCF服务:

PhotoSave: function (d, callback) {
//callback("its been hit", "ok")
    xhr.post({//send data
        url: this.dataServiceUrl + "/PhotoSave",
        postData: dojo.toJson(d),
        contentType: "application/json",
        handleAs: "json",
        load: function (result) {
            callback(result, "ok");

        },
        error: function (err) {
            callback(null, "Error -- photo not inserted.");
        }

    });
}

WCF服务方法:

public String PhotoSave(SByte[] u)
        {
            return "ok";
        }

WCF服务模板:

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "PhotoSave")]
String PhotoSave(SByte[] u);

我收到404无法加载错误。我知道我可以与服务沟通,因为我可以发送一个字符串或int罚款,但这个IntArray给了我一些问题。我出错的任何想法?

我想我的网络配置设置正常:

<services>
          <service name="WatershedSignsService.SignService" behaviorConfiguration="ServiceBehavior">
              <endpoint address="" binding="webHttpBinding" contract="WatershedSignsService.ISignService" behaviorConfiguration="web"/>
          </service>
      </services>
      <bindings>
          <webHttpBinding>
              <binding name="webHttpBindingDev" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
                  <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
              </binding>
          </webHttpBinding>
      </bindings> 

由于

皮特

0 个答案:

没有答案