locked
Is this enough info to create a client / proxy? RRS feed

  • Question

  • Pretty sure I know the answer to this, but i'll ask anyway since i'm new to WCF.

    I have a service (which I did not create) that allows users to login and retrieve the data necessary to consume other services.

    It returns the following:

    • Contract name
    • Contract namespace
    • Extension data
    • Relative location

    Here's the class that holds the info: http://msdn.microsoft.com/en-us/library/hh310509

    I don't see how this can be used to create a proxy. Don't I need an interface class to use with ChannelFactory to do that? I can't use svcutil as the services require login to consume.

    Sunday, August 5, 2012 9:34 PM

Answers

  • You don't need to have exactly that interface as the one that was used in WCF service. You can write your own interface that looks like the interface on WCF service. Matching of method signatures is what matters.

    You can use svcutil even though it requires login, you just need to authenticate first. I am not sure how it is performed through command line, but when I used Visual Studio to generate proxy classes for web services which require authentication, then I first authenticated in that "add service reference..." window, and then I was able to see the WSDL.

    • Marked as answer by LeoTang Sunday, August 12, 2012 11:12 AM
    Monday, August 6, 2012 1:16 PM
  • Hi, if it is a channel factory that you intend to create then you require a binary dependancy against the service. For example, if I have a service that implements an interfacce called IMath, then I must also implment that interface on the client (This is done when svcutil is not used to generate a proxy)

    <ServiceContract()> _
    Public Interface IMath
        <OperationContract()> _
        Function Add(ByVal A As Double, ByVal B As Double) As Double
    End Interface

    If there are any composite types using [DataContract], you must define them also.

    Once I have my interface I am then ready to create a channelfactory. The channel factory below uses wsHttpBinding with message security using a clientcredentialtype of Windows:

            'Create the binding and add Message security
            Dim myBinding As New WSHttpBinding
            myBinding.Security.Mode = SecurityMode.Message
            myBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows
    
            'Create the Endpoint
            Dim myEndpoint As New EndpointAddress("http://MyServer/Math")
    
            'Build the channel factory and apply credentials
            Dim myChannelFactory As ChannelFactory(Of IMath) = New ChannelFactory(Of IMath)(myBinding, myEndpoint)
            myChannelFactory.Credentials.Windows.ClientCredential.UserName = "Domain\Username"
            myChannelFactory.Credentials.Windows.ClientCredential.UserName = "password"
    
            'Create the proxy to the from the channel factory
            Dim wcfClient1 As IMath = myChannelFactory.CreateChannel()
    
            'Use the proxy to exchange some messages
            Dim s As Integer = wcfClient1.Add(3, 39)

    If you don't have the Interface available to you and the metadata exchange endpoint requires authentication to generate a proxy then review my article, WCF, IIS and SSL:

    http://social.technet.microsoft.com/wiki/contents/articles/11510.wcf-iis-and-ssl.aspx

    Scroll down to the bottom of this article until you reach:

    Figure 17: SvcUtil.exe and SvcUtil.exe.config

    This is where you will find information on how to generate metadata from a secure mex endpoint

     
    • Marked as answer by LeoTang Sunday, August 12, 2012 11:12 AM
    Monday, August 6, 2012 2:18 PM

All replies

  • You don't need to have exactly that interface as the one that was used in WCF service. You can write your own interface that looks like the interface on WCF service. Matching of method signatures is what matters.

    You can use svcutil even though it requires login, you just need to authenticate first. I am not sure how it is performed through command line, but when I used Visual Studio to generate proxy classes for web services which require authentication, then I first authenticated in that "add service reference..." window, and then I was able to see the WSDL.

    • Marked as answer by LeoTang Sunday, August 12, 2012 11:12 AM
    Monday, August 6, 2012 1:16 PM