none
System Namespace conflict in WCF Proxy RRS feed

  • Question

  • Hi, I 'm trying to generate a proxy for a WCf service that I created. One of the Operations in the service has a return type WebHeaderCollection which happens to be a part of System.Net Assembly. I'm using the following command to generate the proxy.

    >svcutil.exe /language:cs /out:Proxies/AuthManagerProxy.cs /ct:System.Collections.Generic.List`1 /config:Proxies/out.config https://localhost/OpenAPISecurityManager/AuthManager.svc /serializer:DataContractSerializer

    The problem I'm facing is that the Proxy is containing definition of the root namespaces which is causing conflicts in the client. I can remove the definition manually and everything works fine, however I don;t understand what's the cause for this weird behavior. If I add a service reference using visual studio then I don't face the problem.

    Please refer to line 112 (System.Net) in the code snippet below

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.1008
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    namespace OpenAPISecurityManager.DataContracts
    {
        using System.Runtime.Serialization;
        
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
        [System.Runtime.Serialization.DataContractAttribute(Name="EndpointAccessConfig", Namespace="http://schemas.datacontract.org/2004/07/OpenAPISecurityManager.DataContracts")]
        public partial class EndpointAccessConfig : object, System.Runtime.Serialization.IExtensibleDataObject
        {
            
            private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
            
            private string ApplicationIDField;
            
            private bool disableSignatureField;
            
            private string kevalueField;
            
            private string svcmethodField;
            
            private string svcurlField;
            
            public System.Runtime.Serialization.ExtensionDataObject ExtensionData
            {
                get
                {
                    return this.extensionDataField;
                }
                set
                {
                    this.extensionDataField = value;
                }
            }
            
            [System.Runtime.Serialization.DataMemberAttribute()]
            public string ApplicationID
            {
                get
                {
                    return this.ApplicationIDField;
                }
                set
                {
                    this.ApplicationIDField = value;
                }
            }
            
            [System.Runtime.Serialization.DataMemberAttribute()]
    
            public bool disableSignature
            {
                get
                {
                    return this.disableSignatureField;
                }
                set
                {
                    this.disableSignatureField = value;
                }
            }
            
            [System.Runtime.Serialization.DataMemberAttribute()]
            public string kevalue
            {
                get
                {
                    return this.kevalueField;
                }
                set
                {
                    this.kevalueField = value;
                }
            }
            
            [System.Runtime.Serialization.DataMemberAttribute()]
            public string svcmethod
            {
                get
                {
                    return this.svcmethodField;
                }
                set
                {
                    this.svcmethodField = value;
                }
            }
            
            [System.Runtime.Serialization.DataMemberAttribute()]
            public string svcurl
            {
                get
                {
                    return this.svcurlField;
                }
                set
                {
                    this.svcurlField = value;
                }
            }
        }
    }
    namespace System.Net
    {
        using System;
        
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
        [System.SerializableAttribute()]
        public partial class WebHeaderCollection : System.Collections.Specialized.NameValueCollection
        {
            
            public WebHeaderCollection(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : 
                    base(info, context)
            {
            }
        }
    }
    namespace System.Collections.Specialized
    {
        using System;
        using System.Runtime.Serialization;
        
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
        [System.SerializableAttribute()]
        [System.Runtime.Serialization.KnownTypeAttribute(typeof(System.Net.WebHeaderCollection))]
        public partial class NameValueCollection : System.Collections.Specialized.NameObjectCollectionBase
        {
            
            public NameValueCollection(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : 
                    base(info, context)
            {
            }
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
        [System.SerializableAttribute()]
        [System.Runtime.Serialization.KnownTypeAttribute(typeof(System.Collections.Specialized.NameValueCollection))]
        [System.Runtime.Serialization.KnownTypeAttribute(typeof(System.Net.WebHeaderCollection))]
        public partial class NameObjectCollectionBase : object, System.Runtime.Serialization.ISerializable
        {
            
            private System.Runtime.Serialization.SerializationInfo info;
            
            public NameObjectCollectionBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            {
                this.info = info;
            }
            
            public System.Runtime.Serialization.SerializationInfo SerializationInfo
            {
                get
                {
                    return this.info;
                }
                set
                {
                    this.info = value;
                }
            }
            
            public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            {
                if ((this.SerializationInfo == null))
                {
                    return;
                }
                System.Runtime.Serialization.SerializationInfoEnumerator enumerator = this.SerializationInfo.GetEnumerator();
                for (
                ; enumerator.MoveNext(); 
                )
                {
                    System.Runtime.Serialization.SerializationEntry entry = enumerator.Current;
                    info.AddValue(entry.Name, entry.Value);
                }
            }
        }
    }
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="http://masked/servicecontracts", ConfigurationName="IAuthManager")]
    public interface IAuthManager
    {
        
        [System.ServiceModel.OperationContractAttribute(Action="http://masked/servicecontracts/IAuthManager/CreateSignedHeader", ReplyAction="http://masked/servicecontracts/IAuthManager/CreateSignedHeaderResponse")]
        System.Net.WebHeaderCollection CreateSignedHeader(OpenAPISecurityManager.DataContracts.EndpointAccessConfig endPoint);
        
        [System.ServiceModel.OperationContractAttribute(Action="http://masked/servicecontracts/IAuthManager/CreateSignedBody", ReplyAction="http://masked/servicecontracts/IAuthManager/CreateSignedBodyResponse")]
        string CreateSignedBody(string body, OpenAPISecurityManager.DataContracts.EndpointAccessConfig endPoint);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface IAuthManagerChannel : IAuthManager, System.ServiceModel.IClientChannel
    {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class AuthManagerClient : System.ServiceModel.ClientBase<IAuthManager>, IAuthManager
    {
        
        public AuthManagerClient()
        {
        }
        
        public AuthManagerClient(string endpointConfigurationName) : 
                base(endpointConfigurationName)
        {
        }
        
        public AuthManagerClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress)
        {
        }
        
        public AuthManagerClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress)
        {
        }
        
        public AuthManagerClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress)
        {
        }
        
        public System.Net.WebHeaderCollection CreateSignedHeader(OpenAPISecurityManager.DataContracts.EndpointAccessConfig endPoint)
        {
            return base.Channel.CreateSignedHeader(endPoint);
        }
        
        public string CreateSignedBody(string body, OpenAPISecurityManager.DataContracts.EndpointAccessConfig endPoint)
        {
            return base.Channel.CreateSignedBody(body, endPoint);
        }
    }




    • Edited by LalatNayak Friday, December 13, 2013 2:39 AM More details
    • Moved by Caillen Monday, December 16, 2013 2:07 AM WCF question.
    Friday, December 13, 2013 2:20 AM

Answers

  • Hi,

    Maybe it is because that you are reusing DataContract while generating proxy & old DataContract dll was not replaced in location from where it is referenced.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 19, 2013 10:35 AM
    Moderator

All replies

  • Hi LalatNayak,

    I'm moving your question to WCF forum where you could get more help.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 16, 2013 2:09 AM
  • Hi,

    For the Namespace conflict in wcf, there's a namespace switch on the svcutil.exe utility.

    /namespace:<string,string>

    so, please try to add the option below to map to your own namespace.
    ..... /namespace:*,MyNamespace

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, December 16, 2013 7:48 AM
    Moderator
  • Thanks Amy

    I tried doing the above and got a different error-

    >svcutil.exe /language:cs /out:Proxies/AuthManagerProxy.cs /ct:System.Collections.Generic.List`1 /config:Proxies/out.config https://localhost/OpenAPISecurityManager/AuthManager.svc /serializer:DataContractSerializer /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll" /namespace:*,OpenAPISecurityManager.ServiceProxies

    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Attempting to download metadata from 'https://localhost/OpenAPISecurityManager/AuthManager.svc' using WS-Metadata Exchange or DISCO.Error: Cannot import wsdl:portTypeDetail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporterError: ISerializable type with data contract name 'WebHeaderCollection' in namespace 'http://schemas.datacontract.org/2004/07/System.Net' cannot be imported. The data contract namespace cannot be customized for ISerializable types and the generated namespace 'OpenAPISecurityManager. ServiceProxies' does not match the required CLR namespace 'System.Net'. Check if the required namespace has been mapped to a different data contract namespace and consider mapping it explicitly using the namespaces collection.XPath to Error Source: //wsdl:definitions[@targetNamespace='http://--masked--/servicecontracts']/wsdl:portType[@name='IAuthManager']


    Error: Cannot import wsdl:binding
    Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
    XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://--masked--/servicecontracts']/wsdl:portType[@name='IAuthManager']
    XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='AuthManager']


    Error: Cannot import wsdl:port
    Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
    XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='AuthManager']
    XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/'
    ]/wsdl:service[@name='AuthManager']/wsdl:port[@name='AuthManager']

    Monday, December 16, 2013 4:37 PM
  • Hi,

    Maybe it is because that you are reusing DataContract while generating proxy & old DataContract dll was not replaced in location from where it is referenced.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 19, 2013 10:35 AM
    Moderator
  • Could not understand the above. Can you please elaborate a bit?
    Wednesday, January 8, 2014 4:12 PM