简体   繁体   English

从Java客户端到WCF Web服务的对象,反序列化错误

[英]object from java client to WCF Web service, error deserializing

I have a .NET WCF Web service working great when called from another .NET app. 从另一个.NET应用程序调用时,我有一个.NET WCF Web服务很好用。 Now I was trying to build a Java client to test the service but one of the methods won't work. 现在,我试图构建一个Java客户端来测试服务,但是其中一种方法不起作用。

I try to send a List of updates. 我尝试发送更新列表。 The complex type is: 复杂类型为:

<xs:complexType name="ArrayOfRegisterUpdate">
    <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="OneUpdateRegister"
                    nillable="true" type="tns:OneUpdateRegister" /> 
    </xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfRegisterUpdate" nillable="true" 
    type="tns:ArrayOfRegisterUpdate" /> 
<xs:complexType name="OneUpdateRegister">
    <xs:sequence>
        <xs:element minOccurs="0" name="Field" type="tns:RegisterField" /> 
        <xs:element minOccurs="0" name="Value" nillable="true" type="xs:anyType" /> 
    </xs:sequence>
</xs:complexType>
<xs:element name="OneUpdateRegister" nillable="true" type="tns:OneUpdateRegister" />

My Java Proxy lets me insert any object in "Value", as expected (it could be Strings, ints or DateTimes). 我的Java代理使我可以按预期在“值”中插入任何对象(它可以是Strings,int或DateTimes)。 But if I enter a String, the following Exception launches: 但是,如果我输入一个字符串,则会启动以下异常:

The formatter threw an exception while trying to deserialize the message: 
There was an error while trying to deserialize parameter http://tempuri.org/:updates. 
The InnerException message was 'There was an error deserializing the object of type 
System.Collections.Generic.List`1
[[xxx.xxx.OneUpdateRegister, XXx.XXx, Version=1.0.0.0, Culture=neutral, `PublicKeyToken=null]]. 
The value 'John' cannot be parsed as the type 'Guid.'. Please see InnerException for more details.

The web method doesn't even get called. Web方法甚至没有被调用。 I don't know what does type 'Guid' have to do with all this, I just can see this type in the xsd of simple types. 我不知道类型'Guid'与所有这些有什么关系,我只能在简单类型的xsd中看到此类型。

Any idea? 任何想法? Please let me know any other info that could be useful. 请让我知道其他可能有用的信息。 Thank you. 谢谢。

Where did this fragment of XML Schema come from? XML Schema的这个片段来自哪里?

Can you post the signature of the operation being called, including the [OperationContract]? 您可以张贴被调用操作的签名,包括[OperationContract]吗? Same with the service contract. 与服务合同相同。

What is the signature of the Java proxy that you are calling? 您正在调用的Java代理的签名是什么?

I'm concerned that this schema could validate some XML you might not want. 我担心该架构可能会验证一些您可能不需要的XML。 For instance, did you notice that you could have a sequence of Field, Value, Value? 例如,您是否注意到可以有一个字段,值,值的序列?

That doesn't explain where 'Guid' is coming from, though. 但是,这并不能解释“向导”的来源。

If I try with null or with a DateTime (Calendar in Java) there is no problem. 如果我尝试使用null或DateTime(Java中的Calendar),则没有问题。 Only strings seem to be problematic. 只有字符串似乎有问题。 In the other hand, ints are supposed to be sent as strings so the same problem happens with them. 另一方面,应该将int作为字符串发送,因此它们也会发生相同的问题。

I'm afraid I'm not a real expert in .NEt ws. 恐怕我不是.NEt ws的真正专家。 I guess this is what you asked me for, server side: 我想这是您在服务器端向我要的:

[System.ServiceModel.ServiceContractAttribute(Namespace="http://xx.es/ServiceName/", ConfigurationName="ServiceName.InterfaceName")]
public interface InterfaceName{

    ....

    [System.ServiceModel.OperationContractAttribute(Action="http://xx.es/ServiceName/InterfaceName/UpdateRegister", ReplyAction="http://xx.es/ServiceName/InterfaceName/UpdateRegisterRes" +
        "ponse")]
    package.UpdateRegisterReturn UpdateRegister(string user, string password, int id1, int id2, System.Collections.Generic.List<package.OneUpdateRegister> updates);

        ....
  }

The XML schema from my first entry comes from the server, from file ServiceName.xsd 我的第一个条目的XML模式来自服务器,来自文件ServiceName.xsd

This is the signature of my auto-generated Java proxy: 这是我自动生成的Java代理的签名:

public es.xx.UpdateRegisterReturn updateRegister(java.lang.String user, java.lang.String password, java.lang.Integer id1, java.lang.Integer id2, es.xx.OneUpdateRegister[] updates) throws java.rmi.RemoteException{

May I have to force this java parameter to be a List, even if it was auto-generated like this and even if it works with dates and nulls? 我是否可以强制将此java参数设置为List,即使它是像这样自动生成的,即使它与日期和null一起使用也是如此?

This file (ServiceName1.xsd) is the only place in the whole server solution where I can find Guid type: 该文件(ServiceName1.xsd)是整个服务器解决方案中唯一可以找到Guid类型的位置:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="anyType" nillable="true" type="xs:anyType" />
  <xs:element name="anyURI" nillable="true" type="xs:anyURI" />
  <xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
  <xs:element name="boolean" nillable="true" type="xs:boolean" />
  <xs:element name="byte" nillable="true" type="xs:byte" />
  <xs:element name="dateTime" nillable="true" type="xs:dateTime" />
  <xs:element name="decimal" nillable="true" type="xs:decimal" />
  <xs:element name="double" nillable="true" type="xs:double" />
  <xs:element name="float" nillable="true" type="xs:float" />
  <xs:element name="int" nillable="true" type="xs:int" />
  <xs:element name="long" nillable="true" type="xs:long" />
  <xs:element name="QName" nillable="true" type="xs:QName" />
  <xs:element name="short" nillable="true" type="xs:short" />
  <xs:element name="string" nillable="true" type="xs:string" />
  <xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
  <xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
  <xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
  <xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
  <xs:element name="char" nillable="true" type="tns:char" />
  <xs:simpleType name="char">
    <xs:restriction base="xs:int" />
  </xs:simpleType>
  <xs:element name="duration" nillable="true" type="tns:duration" />
  <xs:simpleType name="duration">
    <xs:restriction base="xs:duration">
      <xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
      <xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
      <xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="guid" nillable="true" type="tns:guid" />
  <xs:simpleType name="guid">
    <xs:restriction base="xs:string">
      <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
    </xs:restriction>
  </xs:simpleType>
  <xs:attribute name="FactoryType" type="xs:QName" />
</xs:schema>

I guess it's an auto-generated generic file. 我想这是一个自动生成的通用文件。

Sorry, I just realised that both xsd are from the test client in .net solution! 抱歉,我刚刚意识到这两个xsd都来自.net解决方案中的测试客户端! Anyway, they may give a clue. 无论如何,他们可能会提供线索。

These are real files from the Web Service: 这些是来自Web服务的真实文件:

[ServiceContract(Namespace = Constants.PublicNamespace)]
    public interface InterfaceName
    {

         ///<summary>
        ///</summary>
        ///<param name="user"></param>
        ///<param name="password"></param>
        ///<param name="id1"></param>
        ///<param name="id2"></param>
        ///<param name="updates"></param>
        ///<returns></returns>
        [OperationContract]
        UpdateRegisterReturn UpdateRegister(
            string user,
            string password,
            int id1,
            int id2,
            List<OneUpdateRegister> updates);

        ... {other methods working just fine}    
    }
}

And this is the class OneUpdateRegister: 这是OneUpdateRegister类:

     ///<summary>
    ///</summary>
    [DataContract(Namespace = Constants.PublicNamespace)]
    public sealed class OneUpdateRegister
    {
        ///<summary>
        ///</summary>
        [DataMember]
        public RegisterField Field { get; set; }

        ///<summary>
        ///</summary>
        [DataMember]
        public object Value{ get; set; } // this is the problematic data member!
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM