CMertens / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

WCF parameters become null when preceding parameter is null #241

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============
jon.cummins@newmotorventures.com
What steps will reproduce the problem?
1. Create basicHttpBingind WCF Service
2. Use common DTO assembly for data transfer
3. Have service with multiple parameters.
4. Specify first parameter as null, all other parameters become null.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
r282

Please provide any additional information below.

IConfiguration.cs

    [ServiceContract]
    public interface IConfiguration
    {
        [OperationContract]
        void LogRender(FullUserData fud, RenderData rd, WebRequestInfo wri);
    }

Configuration.svc.cs

    // NOTE: If you change the class name "Configuration" here, you must also update the reference to "Configuration" in Web.config.
    [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
    public class Configuration : IConfiguration
    {
        public void LogRender(FullUserData fud, myCarFling.Utilities.RenderData rd, WebRequestInfo wri)
        {
            //rd is null if fud is null
        }
    }

DataDef.cs in shared assembly

    [DataContract]
    [ProtoInclude(50, typeof(RenderData))]
    [ProtoInclude(51, typeof(FullUserData))]
    public class BaseDataTransfer
    {
        [DataMember(Order=1)]
        public string Exception;
        public virtual string cacheKey()
        {
            throw new NotImplementedException("Implement Cache Key on this BaseDataTransfer before caching it.");
        }
    }

    [DataContract]
    public class WebRequestInfo
    {
        [DataMember(Order=1)]
        public string userHost;
        [DataMember(Order=2)]
        public string userAgent;
        [DataMember(Order=3)]
        public string userAddress;
    }

   [DataContract]
    public class RenderData : BaseDataTransfer
    {
        [DataMember(Order=1)]
        public Guid RenderData_id { get; set; }
        [DataMember(Order=2)]
        public string Controller { get; set; }
        [DataMember(Order=3)]
        public string Action { get; set; }
        [DataMember(Order=4)]
        public string Id { get; set; }
        [DataMember(Order=5)]
        public string querystring { get; set; }
        [DataMember(Order=6)]
        public int RenderTime { get; set; }
        [DataMember(Order=7)]
        public string WebServer { get; set; }
        [DataMember(Order=8)]
        public DateTime requested { get; set; }
    }

  [DataContract]
    public class FullUserData : BaseDataTransfer
    {
        [DataMember(Order=1)]
        public string sessionHash { get; set; }
        [DataMember(Order=2)]
        public string userName { get; set; }
        [DataMember(Order=3)]
        public string userEmail { get; set; }
        [DataMember(Order=4)]
        public string newPass { get; set; }
        [DataMember(Order=5)]
        public string confirmNewPass { get; set; }
        [DataMember(Order=6)]
        public string userPassHash { get; set; }
        [DataMember(Order=7)]
        public string Zip { get; set; }
        [DataMember(Order=8)]
        public enRoleType[] userRoles { get; set; }
        [DataMember(Order=9)]
        public string DatabaseConn { get; set; }
        [DataMember(Order=10)]
        public string DatabaseName { get; set; }
        [DataMember(Order=11)]
        public string ServerGroup { get; set; }
        [DataMember(Order=12)]
        public Guid UserId { get; set; }
        [DataMember(Order=14)]
        public int ProfilePoints { get; set; }
        [DataMember(Order=15)]
        public bool DisplayHelp { get; set; }
        [DataMember(Order=16)]
        public bool Notifications { get; set; }
        [DataMember(Order=17)]
        public bool Messages { get; set; }
    }

Server web.config
<service behaviorConfiguration="myCarFling.Data.ConfigurationBehavior" 
name="myCarFling.Data.Configuration">
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHTTPBinding" contract="myCarFling.Data.IConfiguration" behaviorConfiguration="Proto.Common.EndpointBehavior">
        <identity>
         <dns value="localhost" />
        </identity>
     </endpoint>
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
        <behaviors>
      <endpointBehaviors>
        <behavior name="Proto.Common.EndpointBehavior">
          <protobuf/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <extensions>
            <behaviorExtensions>
                <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=1.0.0.280, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
            </behaviorExtensions>
        </extensions>

Client web.config 

   <endpoint address="http://localhost:8081/Configuration.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IConfiguration" contract="Configuration.IConfiguration"
    name="BasicHttpBinding_IConfiguration" behaviorConfiguration="Proto.Common.EndpointBehavior"  />

Example Message that ended up with all parameters null

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" 
xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost
:8081/Configuration.svc</To>
<Action s:mustUnderstand="1" 
xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.o
rg/IConfiguration/LogRender</Action>
</s:Header>
<s:Body>
<LogRender xmlns="http://tempuri.org/">
<proto nil="true"></proto>
<proto>kgNDChIJN1Djqn5XCk0RiZBKGCV+2+gSBEhvbWUaBUluZGV4IgAqADD6BzoMSk9FTkFUSEFOL
VBDQgsIqKPmw7CG7S4QBQ==</proto>
<proto>CgkxMjcuMC4wLjESak1vemlsbGEvNS4wIChXaW5kb3dzIE5UIDYuMTsgV09XNjQpIEFwcGxlV
2ViS2l0LzUzNS4xIChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzE0LjAuODM1LjIwMiBTYWZhcmkvN
TM1LjEaCTEyNy4wLjAuMQ==</proto>
</LogRender>
</s:Body>
</s:Envelope>

Example msg that ended up having values for all parameters 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" 
xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost
:8081/Configuration.svc</To>
<Action s:mustUnderstand="1" 
xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.o
rg/IConfiguration/LogRender</Action>
</s:Header>
<s:Body>
<LogRender xmlns="http://tempuri.org/">
<proto>mgMA</proto>
<proto>kgNCChIJYkY0SSQ0XUARq8lAmLyvAE8SBEhvbWUaBUluZGV4IgAqADACOgxKT0VOQVRIQU4tU
ENCCwispJTU1oXtLhAF</proto>
<proto>CgkxMjcuMC4wLjESak1vemlsbGEvNS4wIChXaW5kb3dzIE5UIDYuMTsgV09XNjQpIEFwcGxlV
2ViS2l0LzUzNS4xIChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzE0LjAuODM1LjIwMiBTYWZhcmkvN
TM1LjEaCTEyNy4wLjAuMQ==</proto>
</LogRender>
</s:Body>
</s:Envelope>

Original issue reported on code.google.com by joenath...@gmail.com on 16 Oct 2011 at 4:11

GoogleCodeExporter commented 9 years ago
This was a interesting bug (some subtle XmlReader nuances). Fixed r469

Original comment by marc.gravell on 2 Nov 2011 at 10:00

GoogleCodeExporter commented 9 years ago
glad I could help, I got around it by just reordering paramaters but I'm happy 
to see it won't be a future issue

Original comment by joenath...@gmail.com on 2 Nov 2011 at 11:00

GoogleCodeExporter commented 9 years ago
May I ask, does this bug impact v1 in any way? (We're 'still' using v1 and we 
cannot switch easily)

Original comment by T...@aimproductions.be on 20 Jan 2014 at 12:04