Sharing data types from multiple web links

Suppose the provider provides two separate web services that share the same data types and the same namespace.

eg. The following web services contain similar objects, such as the TestCredentials object:

  • TestWebservice / Testwebservice1.asmx
  • TestWebservice / Testwebservice2.asmx

By including them in Visual Studio using web links, I get:

  • Testwebservice1.TestCredentials
  • Testwebservice2.TestCredentials

When I really want:

  • Testwebservice.TestCredentials

Is there any way in Visual Studio when working with web links to link the two web services together so that the proxy classes they create are the same (and within the same namespace)?

+3
source share
6 answers

Another possible option (along with wsdl.exe / sharetypes) is to use Visual Studio 2008 and use the "Add service link". The Add Service Link dialog box contains options for reusing types.

+2
source

You will have to manually generate your proxy classes using the wsdl.exe program with the / sharetypes switch .

+2
source

, - visual studio, wsdl.exe -, , URL URL- .

+1

, . , .

, WSDL- , ( -).cs - :

, WSDL .

WebReference1.cs


public partial class WebReferenceName1 : System.Web.Services.Protocols.SoapHttpClientProtocol 
{
    // take the methodname and append Local to the end
    public Consolidated.ReturnType MethodName1Local(params)
    {
        // redirect the return value of the call to the consolidation method and return the new value
        return Consolidation.Convert(this.MethodName1(params);
    }
}

-

WebReference2.cs


public partial class WebReferenceName2 : System.Web.Services.Protocols.SoapHttpClientProtocol 
{
    // take the methodname and append Local to the end
    public Consolidated.ReturnType MethodName2Local(params)
    {
        // redirect the return value of the call to the consolidation method and return the new value
        return Consolidation.Convert(this.MethodName2(params);
    }
}

,

Consolidator.cs


public class Consolidation
{
    // Input from Web Reference #1
    public static Consolidated.ReturnType Convert(WebReferenceName1.ReturnType valuetoConvert)
    {
        // Convert from valuetoConvert to Consolidated.ReturnType
        convertedValue = (conversion of valuetoConvert to Consolidated.ReturnType);

        return convertedValue;
    }

    // Input from Web Reference #2
    public static Consolidated.ReturnType Convert(WebReferenceName2.ReturnType valuetoConvert)
    {
        // Convert from valuetoConvert to Consolidated.ReturnType
        convertedValue = (conversion of valuetoConvert to Consolidated.ReturnType);

        return convertedValue;
    }
}

-, {WebMethod} Local(), Consolidator , WSDL, , .

Consolidated.ReturnType - , , , WSDL -. "" / .

0

.disco, -. -.

Visual studio , xml.

0

, , reference.cs.

What comes to mind is a few workarounds: 1) create a reflection-based copy method that copies values ​​based on property names or 2) if you are using .NET 3.5, write an extension method to copy between the two types.

-1
source

Source: https://habr.com/ru/post/1703442/


All Articles