locked
WCF proxy generation issue from VS2010 IDE RRS feed

  • Question

  • i am new in WCF and i am working with VS2010 IDE. in my solution there are 3 projects. one is service including .svc file another one is win form where i hosted the service and another one is winform for making wcf client. i have not ceated any web.config file for svc service type apps but where i hosted my service there i created app.config for end point and metadata. first i run the winform exe where service has been hosted and it is running fine. after running wcf server then i try to create proxy for client win form project just adding service reference. when i put the mex url then i am getting error like Error occur while find the service

    i understand that there is some metadata related problem occur but i am not being able to fix it due to new in WCF area. here is my app.config file details which is created where service has been hosted in win form apps.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.serviceModel>
    <services>
      <service name="WCFService.Service" behaviorConfiguration="behaviorConfig">
    
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:1645/ChatServer/"/>
            <add baseAddress="http://localhost:1648/ChatServer/"/>
          </baseAddresses>
        </host>
        <endpoint address="tcp"
                          binding="netTcpBinding"
                          bindingConfiguration="tcpBinding"
                          contract="ChatService.IChat"/>
    
        <endpoint address="net.tcp://localhost:1645/ChatServer/mex"
                          binding="mexTcpBinding"
                          contract="IMetadataExchange"/>
    
      </service>
    </services>
    
    <behaviors>
      <serviceBehaviors>
        <behavior name="behaviorConfig">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding"
                         maxBufferSize="67108864"
                         maxReceivedMessageSize="67108864"
                         maxBufferPoolSize="67108864"
                         transferMode="Buffered"
                         closeTimeout="00:00:10"
                         openTimeout="00:00:10"
                         receiveTimeout="00:20:00"
                         sendTimeout="00:01:00"
                         maxConnections="100">
          <security mode="None">
          </security>
          <readerQuotas maxArrayLength="67108864"
                                  maxBytesPerRead="67108864"
                                  maxStringContentLength="67108864"/>
          <reliableSession enabled="true" inactivityTimeout="00:20:00"/>
        </binding>
      </netTcpBinding>
      </bindings>
      </system.serviceModel>
      </configuration>

    here i am attaching screen shot of all projects in my solution.

    Wednesday, December 26, 2012 7:06 PM

Answers

  • Hi,

    As Ovais said above you need generate the auxiliary files with svcutil.exe. Open command prompt with Administrator(search cmd after click start of your system). Input instruction like a capture below:

    Then add the service reference for your client by input the service address(e.g net.tcp://localhost:800/ChatServer ) in the add service pop up window, click Go, you will find the service.

    Below is my test code and test steps, for your information.

    1.Create a Service Library, then create a Windows Form application to host the service( exclude the app.config from project).

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ServiceHost host = new ServiceHost(typeof(ServiceLibrary.Service1), new Uri("net.tcp://localhost:800/ChatServer"));
                host.AddServiceEndpoint(typeof(ServiceLibrary.IService1), new NetTcpBinding(), "test");
    
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = false;
                host.Description.Behaviors.Add(smb);
    
                host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
    
                    host.Opened += delegate
                    {
                        label1.Text = "service started!";
    
                    };
                    host.Open();
                
            }
        }

    2.Generate metadata using Svcutil.exe

    3.Add service reference, call the service from a Windows Form application

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
                MessageBox.Show(client.GetData(5).ToString());
            }
        }

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Edited by Haixia_Xie Friday, December 28, 2012 6:16 AM
    • Marked as answer by Mou_kolkata Friday, December 28, 2012 2:05 PM
    Friday, December 28, 2012 6:05 AM

All replies

  • Start the winform application where the service is hosted and perform following step

    1. Open command prompt

    2. Navigate to following Path and execute svcutil.exe followed with the address.

    C:\Program Files\Microsoft Visual Studio 8\VC>svcutil.exe  net.tcp://localhost:1645/ChatServer/mex

    3. It will create a client proxy and a config file just copy and place them under your solution.


    Ovais Mehboob Ahmed Khan http://ovaismehboob.wordpress.com

    Wednesday, December 26, 2012 7:27 PM
  • yes i did but got error called meta data error.
    Thursday, December 27, 2012 3:18 PM
  • Hi,

    As Ovais said above you need generate the auxiliary files with svcutil.exe. Open command prompt with Administrator(search cmd after click start of your system). Input instruction like a capture below:

    Then add the service reference for your client by input the service address(e.g net.tcp://localhost:800/ChatServer ) in the add service pop up window, click Go, you will find the service.

    Below is my test code and test steps, for your information.

    1.Create a Service Library, then create a Windows Form application to host the service( exclude the app.config from project).

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ServiceHost host = new ServiceHost(typeof(ServiceLibrary.Service1), new Uri("net.tcp://localhost:800/ChatServer"));
                host.AddServiceEndpoint(typeof(ServiceLibrary.IService1), new NetTcpBinding(), "test");
    
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = false;
                host.Description.Behaviors.Add(smb);
    
                host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
    
                    host.Opened += delegate
                    {
                        label1.Text = "service started!";
    
                    };
                    host.Open();
                
            }
        }

    2.Generate metadata using Svcutil.exe

    3.Add service reference, call the service from a Windows Form application

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
                MessageBox.Show(client.GetData(5).ToString());
            }
        }

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Edited by Haixia_Xie Friday, December 28, 2012 6:16 AM
    • Marked as answer by Mou_kolkata Friday, December 28, 2012 2:05 PM
    Friday, December 28, 2012 6:05 AM