locked
wcf in windows service with netNamedPipeBinding RRS feed

  • Question

  • Hi,

    I'm trying to host WCF SOAP in Windows service using NetnamedPipe. no matter what i try the client doesn't seem to find the service...

    when using command promt svcutil: 

    SvcUtil.exe /language:cs /out:generatedProxy.cs /config:app.config net.pipe://localhost/SoapCommunication/SoapCommunication/mex

    i get the following error: 

    If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.


    WS-Metadata Exchange Error
        URI: net.pipe://localhost/SoapCommunication/SoapCommunication/mex

        Metadata contains a reference that cannot be resolved: 'net.pipe://localhost/SoapCommunication/SoapCommunication/mex'.

        This request operation sent to net.pipe://localhost/SoapCommunication/SoapCommunication/mex did not receive a reply within the configured timeout (00:05:00).  The time allotted to this operation may have been a portion of a longer timeout.  This may be because the service is still processing the operation or because the service was unable to send a reply message.  Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client.

    after roaming the internet for more than a couple of days this is my last resort...

    code is as follows

    interface:

     [ServiceContract]
        interface ISoapCommunication
        {
            [OperationContract]
            string GetDate();
        }

    class:

    [ServiceBehavior(UseSynchronizationContext = false, ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single)]
        public class SoapCommunication:ISoapCommunication
        {
            public string GetDate()
            {
                return "Date is " + DateTime.Now.ToString();
            }
        }

    web.config:

    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
      </startup>
      <system.serviceModel>
        <services>
          <service name="MyWCFWinSrv.SoapCommunication" behaviorConfiguration="ServiceBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="net.pipe://localhost/SoapCommunication"/>
              </baseAddresses>
            </host>
            <endpoint address ="SoapCommunication" binding="netNamedPipeBinding" contract="MyWCFWinSrv.ISoapCommunication"/>
            <endpoint address ="SoapCommunication/mex" binding="mexNamedPipeBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="basicHttpBindingClient" transferMode="Streamed" messageEncoding="Mtom" maxReceivedMessageSize="10067108864" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </basicHttpBinding>
          <webHttpBinding>
            <binding name="myWebBinding"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" />
          </webHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="false"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
            <behavior name="SimpleService">
              <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="jsonBehavior">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
      <configuration>

    hope to find here help.

    thank you in advance



    Thursday, May 31, 2018 8:23 AM

All replies

  • Hello MeTehila, try specifying the mex endpoint address explicitly. Also, I could be wrong but I believe you want to deliver the metadata as a http request even though the service uses a different protocol. The purpose of the endpoint is to describe the service and not t be called so it does not have to be the same prototocl, just the same service:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/0ca5c79a-ed72-4458-b476-2f4d8477c64f/how-to-get-wsdl-for-a-nettcpbinding-wcf?forum=wcf


    Cheers, Jeff

    Friday, June 1, 2018 12:36 AM
  • hi Jeff,

    Thank you for your reply.

    even when i use the app.config like Microsoft's NetNamedPipes example that i downloaded, it still doesn't work.

    <system.serviceModel>
        <services>
          <service name="WCFNewCEAPI.WCFCommunicationREST">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8000/MyServer"/>
              </baseAddresses>
            </host>
            <endpoint address="/Rest" binding="webHttpBinding" bindingConfiguration="myWebBinding" behaviorConfiguration="jsonBehavior" contract="WCFNewCEAPI.IWCFCommunicationREST"  />
          </service>
          <service name="WCFNewCEAPI.NetPipes" behaviorConfiguration="CalculatorServiceBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8083/ServiceModelSamples/service"/>
              </baseAddresses>
            </host>
            <endpoint address="net.pipe://localhost/ServiceModelSamples/service" binding="netNamedPipeBinding" bindingConfiguration="Binding1" contract="WCFNewCEAPI.INetPipes"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="basicHttpBindingClient" transferMode="Streamed" messageEncoding="Mtom" maxReceivedMessageSize="10067108864" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </basicHttpBinding>
          <netNamedPipeBinding>
            <binding name="Binding1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
              <security mode="Transport">
                <transport protectionLevel="EncryptAndSign"/>
              </security>
            </binding>
          </netNamedPipeBinding>
          <webHttpBinding>
            <binding name="myWebBinding"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" />
          </webHttpBinding>
        </bindings>
        <extensions>
          <behaviorExtensions>
            <add name="crossOriginResourceSharingBehavior" type="WCFNewCEAPI.EnableCrossOriginResourceSharingBehavior, TransferWorker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
          </behaviorExtensions>
        </extensions>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SimpleService">
              <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
            <behavior name="CalculatorServiceBehavior">
              <serviceMetadata httpGetEnabled="True"/>
              <serviceDebug includeExceptionDetailInFaults="False"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="jsonBehavior">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>

    </system.serviceModel>

    Sunday, June 3, 2018 6:02 AM
  • Hi Metehila,

    How did you host WCF Service in Windows Service?

    To check whether there is any issue with Windows Service, I suggest you try this configuration in Console App, will you be able to access the metadata.

    I made a test with configuration below in Console app, it works correctly by "net.pipe://localhost/service/mex"

        <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <services>
                <service name="WCFConsoleApp.Service1">
                    <endpoint address="" binding="basicHttpBinding" contract="WCFConsoleApp.IService1">
                        <identity>
                            <dns value="localhost" />
                        </identity>
                    </endpoint>
                  <endpoint address="netNamedPipe" binding="netNamedPipeBinding" contract="WCFConsoleApp.IService1" />
                  <endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />
                    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
                    <host>
                        <baseAddresses>
                            <add baseAddress="http://localhost:8733/WCFConsoleApp/Service1/" />
                          <add baseAddress="net.pipe://localhost/service/"/>
                        </baseAddresses>
                    </host>
                </service>
            </services>
        </system.serviceModel>
    

    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.

    Monday, June 4, 2018 5:55 AM
  • works when hosted in console but not in windows service for some reason

    Tuesday, June 5, 2018 7:01 AM
  • That is good news. This most likely is a configuration related issue and/or permissions of how the service is hosted. I find this type of issue easiest to resolve by reviewing the service trace log. 

    I suggest turning on service tracing for both the console and windows service and then comparing the result to look for differences.

    https://docs.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing


    Cheers, Jeff

    Tuesday, June 5, 2018 8:57 PM
  • Hi MeTehila,

    I assume the Windows Service do not have permissions, and I would suggest you run the Windows Service under your domain account.

    If it did not work, as the suggestion from chilberto, it would be helpful if you could share us the Tracing log.

    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, June 6, 2018 3:05 AM