none
Generating one proxy class from multiples endpoints RRS feed

  • Question

  • I have this situation I need to Add and Update programmatically Service references in a Visual Studio Project. I already have all the services references in the project but I need to implement the same process that visual studio does, the idea id at the end have the same result, be able to call successfully the service. I am working with svcutil.exe and I am able to get the .wsdl, .config, .cs file
    But my problem is with one specific service reference that has multiple endpoints because it has different contracts, in this case, the .svcmap file for this particular reference looks like this:

       
     <?xml version="1.0" encoding="utf-8"?>
        <ReferenceGroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="" xmlns="urn:schemas-microsoft-com:xml-wcfservicemap"> 
         <ClientOptions>
            <GenerateAsynchronousMethods>false</GenerateAsynchronousMethods>
            <GenerateTaskBasedAsynchronousMethod>true</GenerateTaskBasedAsynchronousMethod>  
            <EnableDataBinding>true</EnableDataBinding> 
            <ExcludedTypes />
            <ImportXmlTypes>false</ImportXmlTypes>
            <GenerateInternalTypes>false</GenerateInternalTypes>
            <GenerateMessageContracts>false</GenerateMessageContracts>
            <NamespaceMappings />
            <CollectionMappings />
            <GenerateSerializableTypes>true</GenerateSerializableTypes>
            <Serializer>Auto</Serializer>
            <UseSerializerForFaults>true</UseSerializerForFaults>
            <ReferenceAllAssemblies>true</ReferenceAllAssemblies>
            <ReferencedAssemblies />
            <ReferencedDataContractTypes />
            <ServiceContractMappings />
          </ClientOptions>
          <MetadataSources>        
            <MetadataSource Address="https://...../MyService.svc?wsdl" Protocol="http" SourceId="1" />
          </MetadataSources>
          <Metadata>        
            <MetadataFile FileName="serviceFile.wsdl" MetadataType="Wsdl" ID="myId" SourceId="1" SourceUrl="https://.../Service.svc?wsdl=wsdl0" />
            <MetadataFile FileName="serviceFile1.wsdl" MetadataType="Wsdl" ID="myId1" SourceId="1" SourceUrl="https://.../Service.svc?wsdl=wsdl1" />
            <MetadataFile FileName="serviceFile2.wsdl" MetadataType="Wsdl" ID="myId2" SourceId="1" SourceUrl="https://.../Service.svc?wsdl=wsdl2"  />
            <MetadataFile FileName="serviceFile3.wsdl" MetadataType="Wsdl" ID="myId3" SourceId="1" SourceUrl="https://.../Service.svc?wsdl=wsdl3"  />
            <MetadataFile FileName="serviceFile4.wsdl" MetadataType="Wsdl" ID="myId4" SourceId="1" SourceUrl="https://.../Service.svc?wsdl=wsdl4"  />
            <MetadataFile FileName="serviceFile5.wsdl" MetadataType="Wsdl" ID="myId5" SourceId="1" SourceUrl="https://.../Service.svc?wsdl=wsdl5"  />
            <MetadataFile FileName="serviceFile6.wsdl" MetadataType="Wsdl" ID="myId6" SourceId="1" SourceUrl="https://.../Service.svc?wsdl=wsdl6"  />
          </Metadata>
          <Extensions>
            <ExtensionFile FileName="configuration91.svcinfo" Name="configuration91.svcinfo" />
            <ExtensionFile FileName="configuration.svcinfo" Name="configuration.svcinfo" />
          </Extensions>
        </ReferenceGroup>
    

    and the Service Reference folder contains the following files:

        - *.datasource
        - *.svcinfo
        - *.wsdl (one file for each endpoint)
        - .svcmap
        - Reference.cs (just one proxy class)


    The visual studio creates just one .cs file with all the partial class and interfaces for each service for each endpoint.

    The svcutil.exe generate and retrieve all the *.wsdl files for each endpoint, and a .cs file for each endpoint also. I would like to know if is possible end with just one .cs file like the Visual Studio does. I tried to pass more that one url to the svcutil.exe but that give me some errors. Is there any other way to do that??
    Can someone explain more about the proxy classes when I have multiples endpoints for one service.
    Tuesday, December 5, 2017 1:30 PM

All replies

  • Hi yfrancisco,

    >> one specific service reference that has multiple endpoints because it has different contracts

    What do you mean by one service with multiple endpoints? What command in svcutil.exe did you use?

    I made a test with two Service classes which inherit the same Service Contracts, and two services classes which inherit different Service Contracts, the command below outputs to one .cs file.

    It would be helpful if you could share us a simple project and detail steps to reproduce your issue.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 6, 2017 1:51 AM
  • Hi,

    I am using this command:

    svcutil $file.FullName /out:$name  /tcv:version35 /serializable /enableDataBinding /n:*,$namespace /directory:$directory 

    where $file is one of the .wsdl files from the service. 

    When I update the service on VisualStudio I just get one single .cs file, and my projects build and run successfully, but when I am using <g class="gr_ gr_10 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="10" id="10">svcutil</g> what I do is that I run first:

     svcutil /t:metadata /directory:$directory $address

    That give me all the <g class="gr_ gr_25 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="25" id="25">wsdl</g> files and then I have to run the first command for each file and I get the proxy classes. At the beginning, I thought that the service was backward compatible and that I just will need to get the proxy class with the newest WSDL file, but that was wrong if I replace the Reference.cs from the Visual Studio with that file my project doesn't build. I am trying to know how to get just one file and not just one for each <g class="gr_ gr_26 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="26" id="26">wsdl</g> file.

    And also in a case that the solution is just merging all the .cs files I would like to know if there is a way when I generate the files don't generate the redundancy. 


    • Edited by yfrancisco Wednesday, December 6, 2017 7:35 PM
    Wednesday, December 6, 2017 3:57 PM
  • Hi yfrancisco,

    >> When I update the service on VisualStudio I just get one single .cs file

    Which wsdl file did you use when updating service on VS? If you try svcutil with the same wsdl file, will it create multiple .cs files?

    Based on your description, it seems you create multiple wsdl files first by svcutil, and then generate client code by generated wsdl files. For multiple wsdl files, it is expected result that you need to run svcutil command for every wsdl file and they will generate separated cs file. As the available command options for svcutil, there is no way to combine different wsdl files or merge the generated cs file into one file.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 7, 2017 3:09 AM