verwenden svcutil zuordnen mehrerer namespaces für die Erzeugung von wcf-service Proxy

Will ich mit svcutil map mehrere wsdl-namespace auf den clr-namespace beim generieren von service-proxies. Ich verwende starke Versionierung von namespaces und damit die erzeugte clr-namespaces sind peinlich und können bedeuten, dass viele client-seitige code ändert sich, wenn die wsdl/xsd-namespace-version verpasst. Ein code-Beispiel wäre besser zu zeigen, was ich will.

//Service code
namespace TestService.StoreService
{
    [DataContract(Namespace = "http://mydomain.com/xsd/Model/Store/2009/07/01")]
    public class Address
    {
        [DataMember(IsRequired = true, Order = 0)]
        public string street { get; set; }
    }

    [ServiceContract(Namespace = "http://mydomain.com/wsdl/StoreService-v1.0")]
    public interface IStoreService
    {
        [OperationContract]
        List<Customer> GetAllCustomersForStore(int storeId);

        [OperationContract]
        Address GetStoreAddress(int storeId);
    }

    public class StoreService : IStoreService
    {
        public List<Customer> GetAllCustomersForStore(int storeId)
        {
            throw new NotImplementedException();
        }

        public Address GetStoreAddress(int storeId)
        {
            throw new NotImplementedException();
        }
    }
}

namespace TestService.CustomerService
{
    [DataContract(Namespace = "http://mydomain.com/xsd/Model/Customer/2009/07/01")]
    public class Address
    {
        [DataMember(IsRequired = true, Order = 0)]
        public string city { get; set; }
    }

    [ServiceContract(Namespace = "http://mydomain.com/wsdl/CustomerService-v1.0")]
    public interface ICustomerService
    {
        [OperationContract]
        Customer GetCustomer(int customerId);

        [OperationContract]
        Address GetStoreAddress(int customerId);
    }

    public class CustomerService : ICustomerService
    {
        public Customer GetCustomer(int customerId)
        {
            throw new NotImplementedException();
        }

        public Address GetStoreAddress(int customerId)
        {
            throw new NotImplementedException();
        }
    }
}

namespace TestService.Shared
{
    [DataContract(Namespace = "http://mydomain.com/xsd/Model/Shared/2009/07/01")]
    public class Customer
    {
        [DataMember(IsRequired = true, Order = 0)]
        public int CustomerId { get; set; }
        [DataMember(IsRequired = true, Order = 1)]
        public string FirstName { get; set; }
    }
}

1. svcutil - ohne namespace-Zuordnung

svcutil.exe /t:metadata 
    TestSvcUtil\bin\debug\TestService.CustomerService.dll     
    TestSvcUtil\bin\debug\TestService.StoreService.dll

svcutil.exe /t:code *.wsdl *.xsd /o:TestClient\WebServiceProxy.cs

Den generierten proxy sieht aus wie

namespace mydomain.com.xsd.Model.Shared._2009._07._011
{
    public partial class Customer{}
}
namespace mydomain.com.xsd.Model.Customer._2009._07._011
{
    public partial class Address{}
}
namespace mydomain.com.xsd.Model.Store._2009._07._011
{
    public partial class Address{}
}

Client-Klassen sind von namespaces. Jede änderung der xsd-Namensraum implizieren würde Sie alle using-Anweisungen in mein client-code zu bauen, zu brechen.

2. svcutil - mit wildcard-namespace-Zuordnung

svcutil.exe /t:metadata 
    TestSvcUtil\bin\debug\TestService.CustomerService.dll 
    TestSvcUtil\bin\debug\TestService.StoreService.dll

svcutil.exe /t:code *.wsdl *.xsd /n:*,MyDomain.ServiceProxy 
    /o:TestClient\WebServicesProxy2.cs

Den generierten proxy sieht aus wie

namespace MyDomain.ServiceProxy
{
    public partial class Customer{}
    public partial class Address{}
    public partial class Address1{}
    public partial class CustomerServiceClient{}
    public partial class StoreServiceClient{}
}

Beachten Sie, dass svcutil hat sich automatisch verändert, eine der Address-Klasse auf Adresse1. Ich weiß nicht, wie diese. Alle client-Klassen werden auch innerhalb des gleichen namespace.

, Was ich will

Etwas wie dieses:

svcutil.exe 
    /t:code *.wsdl *.xsd 
    /n:"http://mydomain.com/xsd/Model/Shared/2009/07/01, MyDomain.Model.Shared;http://mydomain.com/xsd/Model/Customer/2009/07/01, MyDomain.Model.Customer;http://mydomain.com/wsdl/CustomerService-v1.0, MyDomain.CustomerServiceProxy;http://mydomain.com/xsd/Model/Store/2009/07/01, MyDomain.Model.Store;http://mydomain.com/wsdl/StoreService-v1.0, MyDomain.StoreServiceProxy" 
    /o:TestClient\WebServiceProxy3.cs

Diese Weise kann ich logischerweise Gruppe der clr-namespace, und jede änderung auf die wsdl/xsd-namespace verarbeitet wird, in der proxy-Generierung nur ohne den rest von der client-Seite code.

Nun, das ist nicht möglich. Die svcutil ermöglicht das anzeigen nur eines oder alle Namensräume, nicht eine Liste der Zuordnungen.

Kann ich tun, eins-Zuordnung wie unten gezeigt, aber nicht mehrere

svcutil.exe 
    /t:code *.wsdl *.xsd 
    /n:"http://mydomain.com/xsd/Model/Store/2009/07/01, MyDomain.Model.Address" 
    /o:TestClient\WebServiceProxy4.cs

Aber gibt es eine Lösung. Svcutil ist keine Magie, es ist geschrieben .Net und programmgesteuert generieren des Proxys. Hat jemand geschrieben, eine Alternative zu svcutil oder zeigen Sie mir Richtungen, so dass ich schreiben kann.

Was passiert, wenn Sie nur "Add Service Reference"?
Ich habe nicht versucht, da ich das svcutil zum generieren von proxy dll. Aber ich denke, da "add service reference" - option zur Eingabe nur einen namespace es wäre das gleiche, als wildcard-namespace mapping.

InformationsquelleAutor softveda | 2009-07-09

Schreibe einen Kommentar