0

I have my WCF service returning data both in XML and JSON format.

One functios has to return a List, because I don't know which class will be used to fill this list.

So, I have my class:

public class WrapHome
{
    public WrapHome() { }

    private string p_TITOLO { get; set; }
    public string TITOLO { get { return p_TITOLO.ToString(); } set { p_TITOLO = value; } }

    private List<object> p_CHART { get; set; }
    public List<object> CHART { get { return p_CHART; } set { p_CHART = value; } }
}

and my WCF declaration:

[OperationContract]
[WebGet(UriTemplate = "datiHome.xml?token={token}&p1={p1}&p2={p2}", ResponseFormat = WebMessageFormat.Xml)]
List<WrapHome> GetDatiHomeXML(string token, string p1, string p2);

The output is correctly set, but, when it has to return it converted in XML (or JSON), it re-calls the method and finally give the err_connection_reset error.

I know the problem is the List, because if I comment it, it works. How can I use my List in my WCF output?

If you need more details, ask me without any problem.


Merging multiple JPGs from stdin into multi-file TIFF

I currently have the following command line with ImageMagick:

convert jpg:- -density 200x200 -monochrome -colors 2 -compress Group4 tif:-

I would like to be able to pipe more than one JPG image in stdin, and have those merged into a multi-file TIFF

More precisely, I am doing this from Java via ProcessBuilder, so I am not able to (easily or safely) do things like convert jpg:fd1 ....

I have tried merging all the JPG files into a single byte[] in Java and writing that to the sub-processes stdin, but the result was that ImageMagick only processed the first JPG.

Is what I want to do possible?

4

3 回答 3

1

你可以定义

[KnownType(typeof(MyChildObject0))]
...
[KnownType(typeof(MyChildObjectM))]
public class MyBaseObject { ... }

public class MyChildObject0 : MyBaseObject { ... }
...
public class MyChildObjectM : MyBaseObject { ... }

或者您可以只添加一次属性并定义一次返回所有 M+1 类型的静态方法。

并修改:

public class WrapHome
{
  ...
  public List<MyBaseObject> CHART { get;set; }
}
于 2016-05-24T13:58:45.323 回答
1

就我而言,解决方案更简单。

我有一门课,我所有的方法都回来了,像这样:

[DataContract]
public class Result
    {

        [DataMember]
        public string KeyMensaje;
        [DataMember]
        public string ErrorMessage;        
        [DataMember]        
        public object Objeto;

        ...
   }

问题出Objeto object在这个类里面。该对象用于返回变量类型,如果是复杂对象则不能序列化,例如:

res = new Result(list, "ok", "", "", "", null);  
return res;

在这种情况下object (list)是其他自定义对象的列表,例如List<CustomEmployee>

解决方案是在顶级 Result 类上添加可能的复杂类型object,如下所示:

[DataContract]
[KnownType(typeof(List<CustomEmployee>))]
[KnownType(typeof(CustomEmployee))]
public class Result
{
   ...
}
于 2018-07-23T10:03:49.270 回答
0

为了让它工作,你的服务必须知道它需要序列化的类型。如果无法通过查看方法的签名找到它们(例如,因为一种类型是object),则需要列出所有可能在该 中的类型object

foo将它们注释到您的服务类的顶部,例如,如果您列出可以有,bar和的实例baz

[ServiceKnownType(typeof(foo))]
[ServiceKnownType(typeof(bar))]
[ServiceKnownType(typeof(baz))]
于 2018-07-23T16:37:07.543 回答