Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

RECHERCHER LES VILLES SUIVANT LE CODEPOSTAL VIA UN WEBSERVICE


Information sur la source

Catégorie :ASP.Net Source .NET ( DotNet ) Classé sous : codepostal, postalcode, webservice, serviceweb, webservice Niveau : Initié Date de création : 05/04/2004 Vu / téléchargé: 13 158 / 347

Note :
3 / 10 - par 2 personnes
3,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note


Description

Ce code permet de trouver les villes en fonctions du code postal. Ce code fonctionne en France.

Le webservice utilisé se situe ici : http://www.e-naxos.com/scripts/enwscp.dll/wsdl/IODCODESPOSTAUX

Je vous ai fait une petite classe et une dll qui permet de s'en servir tres facilement.

pour s'en servir il faut tout simplement mettre la dll dans votre dossier bin.

Voici un exemple :

Dim LesVilles As New Cyril.Utility.CodePostal(_CodePostal)
_Villes = LesVilles.GetVille

_villes sera un tableau de string contenant toutes les villes du code postal

j'ai fait une gestion des erreurs il reste surement qq bugs.

J'utilise dans le code une autre de mes classe : la classe validation pour valider le code postal vous trouverez le code ici : http://www.aspfr.com/code.aspx?ID=21651

Dans la dll il y a d'autre chose, ce qui nous interesse et la classe CodePostal qui se situe dans le Namespace Cyril.Utility

Je me sers également du namespace Cyril.Utility.Webservice et de sa classe IODCODESPOSTAUXservice qui est automatiquement généré par VS.net



 

Source

  • Namespace Cyril.Utility
  • ''' -----------------------------------------------------------------------------
  • ''' Project : Cyril
  • ''' Class : Utility.CodePostal
  • '''
  • ''' -----------------------------------------------------------------------------
  • ''' <summary>
  • ''' Cette classe met en relation le webservice
  • ''' http://www.e-naxos.com/scripts/enwscp.dll/wsdl/IODCODESPOSTAUX
  • ''' pour asp.net
  • '''
  • ''' </summary>
  • ''' <remarks>
  • ''' </remarks>
  • ''' <history>
  • ''' [DURAND Cyril] 02/04/2004 Created
  • ''' </history>
  • ''' -----------------------------------------------------------------------------
  • Public Class CodePostal
  • Private _CP As String
  • #Region "Exception"
  • Private Class NotValidCodePostalException
  • Inherits ArgumentException
  • Public Overrides ReadOnly Property Message() As String
  • Get
  • Return "Le code postal demandé était invalide"
  • End Get
  • End Property
  • End Class
  • Private Class NotFoundCodePostalException
  • Inherits ArgumentException
  • Public Overrides ReadOnly Property Message() As String
  • Get
  • Return "Le code postal demandé est introuvable"
  • End Get
  • End Property
  • End Class
  • #End Region
  • ''' -----------------------------------------------------------------------------
  • ''' <summary>
  • '''
  • ''' </summary>
  • ''' <param name="CP"> Code Postal de la ville recherché </param>
  • ''' <remarks>
  • ''' </remarks>
  • ''' <history>
  • ''' [DURAND Cyril] 31/03/2004 Created
  • ''' </history>
  • ''' -----------------------------------------------------------------------------
  • Public Sub New(ByVal CP As String)
  • _CP = CP
  • End Sub
  • Public ReadOnly Property GetVille() As String()
  • Get
  • Try
  • Dim Valid As New Cyril.Utility.Validation.StringValidation
  • If Valid.isCodePostal(_CP) Then
  • Dim LesVilles As New Webservice.IODCODESPOSTAUXservice
  • Dim sGetVille As String
  • sGetVille = LesVilles.GetTownForZip(_CP.ToString, "|")
  • sGetVille = Replace(sGetVille, _CP.ToString & "=", "")
  • GetVille = sGetVille.Split("|")
  • LesVilles.Dispose()
  • Else
  • Throw New NotValidCodePostalException
  • End If
  • Catch ex As NotValidCodePostalException
  • Throw New NotValidCodePostalException
  • Catch ex As Exception
  • Throw New NotFoundCodePostalException
  • End Try
  • End Get
  • End Property
  • Public ReadOnly Property GetPrefecture() As String
  • Get
  • Try
  • Dim Valid As New Cyril.Utility.Validation.StringValidation
  • If Valid.isCodePostal(_CP) Then
  • Dim LesVilles As New Webservice.IODCODESPOSTAUXservice
  • GetPrefecture = LesVilles.GetDepartmentAdminCenterForCode(GetDepartementNumber)
  • LesVilles.Dispose()
  • Else
  • Throw New NotValidCodePostalException
  • End If
  • Catch ex As NotValidCodePostalException
  • Throw New NotValidCodePostalException
  • Catch ex As Exception
  • Throw New NotFoundCodePostalException
  • End Try
  • End Get
  • End Property
  • Public ReadOnly Property GetDepartementNumber() As String
  • Get
  • Dim Valid As New Cyril.Utility.Validation.StringValidation
  • If Valid.isCodePostal(_CP) Then
  • Return Left(_CP, 2)
  • Else
  • Throw New NotValidCodePostalException
  • End If
  • End Get
  • End Property
  • Public ReadOnly Property GetDepartement() As String
  • Get
  • Try
  • Dim Valid As New Cyril.Utility.Validation.StringValidation
  • If Valid.isCodePostal(_CP) Then
  • Dim LesVilles As New Webservice.IODCODESPOSTAUXservice
  • GetDepartement = LesVilles.GetDepartmentForCode(GetDepartementNumber)
  • LesVilles.Dispose()
  • Else
  • Throw New NotValidCodePostalException
  • End If
  • Catch ex As NotValidCodePostalException
  • Throw New NotValidCodePostalException
  • Catch ex As Exception
  • Throw New NotFoundCodePostalException
  • End Try
  • End Get
  • End Property
  • End Class
  • End Namespace
Namespace Cyril.Utility

    ''' -----------------------------------------------------------------------------
    ''' Project	 : Cyril
    ''' Class	 : Utility.CodePostal
    ''' 
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Cette classe met en relation le webservice 
    ''' http://www.e-naxos.com/scripts/enwscp.dll/wsdl/IODCODESPOSTAUX
    ''' pour asp.net
    ''' 
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[DURAND Cyril]	02/04/2004	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Class CodePostal

        Private _CP As String

#Region "Exception"
        Private Class NotValidCodePostalException
            Inherits ArgumentException

            Public Overrides ReadOnly Property Message() As String
                Get
                    Return "Le code postal demandé était invalide"
                End Get
            End Property
        End Class
        Private Class NotFoundCodePostalException
            Inherits ArgumentException

            Public Overrides ReadOnly Property Message() As String
                Get
                    Return "Le code postal demandé est introuvable"
                End Get
            End Property
        End Class
#End Region

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="CP"> Code Postal de la ville recherché </param>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[DURAND Cyril]	31/03/2004	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Sub New(ByVal CP As String)

            _CP = CP
        End Sub

        Public ReadOnly Property GetVille() As String()
            Get
                Try
                    Dim Valid As New Cyril.Utility.Validation.StringValidation
                    If Valid.isCodePostal(_CP) Then

                        Dim LesVilles As New Webservice.IODCODESPOSTAUXservice

                        Dim sGetVille As String
                        sGetVille = LesVilles.GetTownForZip(_CP.ToString, "|")
                        sGetVille = Replace(sGetVille, _CP.ToString & "=", "")

                        GetVille = sGetVille.Split("|")
                        LesVilles.Dispose()

                    Else
                        Throw New NotValidCodePostalException
                    End If

                Catch ex As NotValidCodePostalException
                    Throw New NotValidCodePostalException

                Catch ex As Exception
                    Throw New NotFoundCodePostalException

                End Try

            End Get
        End Property

        Public ReadOnly Property GetPrefecture() As String
            Get
                Try
                    Dim Valid As New Cyril.Utility.Validation.StringValidation
                    If Valid.isCodePostal(_CP) Then

                        Dim LesVilles As New Webservice.IODCODESPOSTAUXservice

                        GetPrefecture = LesVilles.GetDepartmentAdminCenterForCode(GetDepartementNumber)
                        LesVilles.Dispose()

                    Else
                        Throw New NotValidCodePostalException
                    End If

                Catch ex As NotValidCodePostalException
                    Throw New NotValidCodePostalException

                Catch ex As Exception
                    Throw New NotFoundCodePostalException

                End Try

            End Get
        End Property
        Public ReadOnly Property GetDepartementNumber() As String
            Get
                Dim Valid As New Cyril.Utility.Validation.StringValidation
                If Valid.isCodePostal(_CP) Then

                    Return Left(_CP, 2)

                Else
                    Throw New NotValidCodePostalException
                End If

            End Get
        End Property
        Public ReadOnly Property GetDepartement() As String
            Get
                Try
                    Dim Valid As New Cyril.Utility.Validation.StringValidation
                    If Valid.isCodePostal(_CP) Then

                        Dim LesVilles As New Webservice.IODCODESPOSTAUXservice

                        GetDepartement = LesVilles.GetDepartmentForCode(GetDepartementNumber)
                        LesVilles.Dispose()

                    Else
                        Throw New NotValidCodePostalException
                    End If

                Catch ex As NotValidCodePostalException
                    Throw New NotValidCodePostalException

                Catch ex As Exception
                    Throw New NotFoundCodePostalException

                End Try
            End Get
        End Property


    End Class

End Namespace

Conclusion

J'ai encore pas vu de bug mais je suis pas sur à 100%

Je vais bientot mettre un composant qui sera composé d'un textbox et d'un dropdownlist mais en cours de finalisation donc patience

Vous pouvez trouver la version de la dll la plus recente ici : http://jesusonline.free.fr/Cyril/

Dans le zip il y a la dll les commentaires generé automatiquement pas VS.net et les fichiers de code
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !