views:

1195

answers:

4

I have a .NET WCF Web service working great when called from another .NET app. Now I was trying to build a Java client to test the service but one of the methods won't work.

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). 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. 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.

Any idea? Please let me know any other info that could be useful. Thank you.

A: 

If I try with null or with a DateTime (Calendar in Java) there is no problem. 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.

+1  A: 

Where did this fragment of XML Schema come from?

Can you post the signature of the operation being called, including the [OperationContract]? Same with the service contract.

What is the signature of the Java proxy that you are calling?

I'm concerned that this schema could validate some XML you might not want. 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.

John Saunders
A: 

I'm afraid I'm not a real expert in .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

This is the signature of my auto-generated Java proxy:

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?

This file (ServiceName1.xsd) is the only place in the whole server solution where I can find Guid type:

<?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"&gt;
  <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.

Thanks. I'm not clear on where that error message is coming from. It doesn't look like a .NET Exception, yet it mentions .NET types and assemblies. If it's an exception, can you post the whole thing? Catch the exception and then post ex.ToString(). It would also be good if you could post the XML being sent to the service. Also I'd like the definition of the RegisterField type.
John Saunders
A: 

Sorry, I just realised that both xsd are from the test client in .net solution! Anyway, they may give a clue.

These are real files from the Web Service:

[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:

     ///<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!
    }