Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从JS/TS(Angular 2)向WCF发送对象数组?_Javascript_C#_Angular_Wcf_Typescript - Fatal编程技术网

Javascript 从JS/TS(Angular 2)向WCF发送对象数组?

Javascript 从JS/TS(Angular 2)向WCF发送对象数组?,javascript,c#,angular,wcf,typescript,Javascript,C#,Angular,Wcf,Typescript,我必须发送一组这样的对象 [{"Cod":"1"},{"Cod":"5"}] 到我的C#WCF服务,我一直使用到今天,wsHttpBinding没有问题(所以这里没有JSON,只有XML) 请求POST包含以下参数: let param = "<cod>" + data + "</cod>"; 其中CompositeType是: [DataContract] public class CompositeType { string cod; [

我必须发送一组这样的对象

[{"Cod":"1"},{"Cod":"5"}]
到我的C#WCF服务,我一直使用到今天,wsHttpBinding没有问题(所以这里没有JSON,只有XML)

请求POST包含以下参数:

   let param = "<cod>" + data + "</cod>";
其中CompositeType是:

 [DataContract]
public class CompositeType
{
    string cod;

    [DataMember]
    public string Cod
    {
        get { return cod; }
        set { cod = value; }
    }
}
我尝试了很多方法,例如将参数更改为:

  • Object[]cod
  • 列出cod
每次我遇到这个错误(翻译):

这是我要发送的邮件:

"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">" +
  "<s:Header>" +
  "<a:Action s:mustUnderstand=\"1\">http://tempuri.org/IService1/" + GetArrayOfObjects + "</a:Action>" +
  "</s:Header>" +
  "<s:Body>" +
  "<" + GetArrayOfObjects + " xmlns=\"http://tempuri.org/\">" +
  param +
  "</" + GetArrayOfObjects + ">" +
  "</s:Body>" +
  "</s:Envelope>";
“”+
"" +
"" +
"http://tempuri.org/IService1/“+GetArrayOfObjects+”+
"" +
"" +
"" +
param+
"" +
"" +
"";
其中,
param
之前已定义。参数内的
数据的JSON.stringify给出了这个问题的第一个示例(
[{“Cod”:“1”},{“Cod”:“5”}]
)。使用单值参数时,此post消息总是很好

一些网站展示了一个在wcf上使用json反序列化器的解决方案,但我使用的是XML…现在不能用json重新实现该项目


我试了一天,但没有找到解决办法,我很想听听你的解决办法!感谢大家。

您是如何发布数据的?您是否向post请求中添加了数据类型?是的,我始终使用:{“内容类型”:“应用程序/soap+xml;字符集=utf-8”}正在发布的数据是什么样子的?看起来像是格式问题。感谢双方的帮助!请检查我的问题的最后一次编辑,我上传了帖子,并解释了发送的“参数”。你是如何发布数据的?您是否向post请求中添加了数据类型?是的,我始终使用:{“内容类型”:“应用程序/soap+xml;字符集=utf-8”}正在发布的数据是什么样子的?看起来像是格式问题。感谢双方的帮助!请检查我的问题的最后一次编辑,我上传了帖子,并解释了发送的“参数”。
Exception generated by the formatter in an attempt to deserialize the message: Error trying to deserialize the parameter http://tempuri.org/:cod.  InnerException: 'Error at line 1 position 341. Expected status 'Element' .. Found 'Text' with '' name space ''. '.  
...
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">" +
  "<s:Header>" +
  "<a:Action s:mustUnderstand=\"1\">http://tempuri.org/IService1/" + GetArrayOfObjects + "</a:Action>" +
  "</s:Header>" +
  "<s:Body>" +
  "<" + GetArrayOfObjects + " xmlns=\"http://tempuri.org/\">" +
  param +
  "</" + GetArrayOfObjects + ">" +
  "</s:Body>" +
  "</s:Envelope>";