none
The remote server returned an error: NotFound WCF Service RRS feed

  • Question

  • I am building a windows application (not a web service) that is hosting WCF service. When I try to connect from the client and call a very simple function, I get the error in the title (the client is Windows Phone 8). Below is the code. Any pointers would be really appreciated since this is my first time doing WCF

    The service is really simple, that's the code for the service:

      [ServiceContract]
        public interface ITestingService
        {
            [OperationContract]
            Dictionary<string, byte[]> GetData();
        }
    
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
        public class TestingServiceProxy : ITestingService
        {
            public Dictionary<string, byte[]> GetData()
            {
                System.Windows.MessageBox.Show("cheese");
                return GlobalSettings.PhoneFiles;
            }
        }


    And this is the app.config file:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
      <appSettings>
      </appSettings>
      <system.serviceModel>
        <services>
          <service name="Microsoft.IPE.CUTester.TestingServiceProxy" behaviorConfiguration="MyBehavior">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="TcpBinding_ITestingService" contract="Microsoft.IPE.CUTester.ITestingService"/>
            <endpoint address="mex"  binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="MyBehavior">
              <serviceMetadata />
              <serviceThrottling maxConcurrentSessions="10000"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
        <bindings>
          <basicHttpBinding>
            <binding name="TcpBinding_ITestingService" maxReceivedMessageSize="82345678">
              <security mode="None"/>
            </binding>
          </basicHttpBinding>
        </bindings>
      </system.serviceModel>
    </configuration>
    


    And this is how I start the service:

    Uri uri = new Uri("http://localhost:22222/testingservice");
                serviceHost = new ServiceHost(typeof(TestingServiceProxy), uri);
                serviceHost.Open();


    On the client side, this is the code that I have for the service (was initially auto generated and then modified):

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.18449
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    
    
    using System.Collections.Generic;
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName = "ITestingService")]
    public interface ITestingService
    {
        [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action = "http://tempuri.org/ITestingService/GetData", ReplyAction = "http://tempuri.org/ITestingService/GetDataResponse")]
        System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState);
    
        Dictionary<string, byte[]> EndGetData(System.IAsyncResult result);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface ITestingServiceChannel : ITestingService, System.ServiceModel.IClientChannel
    {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class GetDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
    {
    
        private object[] results;
    
        public GetDataCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }
    
        public Dictionary<string, byte[]> Result
        {
            get
            {
                base.RaiseExceptionIfNecessary();
                return ((Dictionary<string,byte[]>)(this.results[0]));
            }
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class TestingServiceClient : System.ServiceModel.ClientBase<ITestingService>, ITestingService
    {
    
        private BeginOperationDelegate onBeginGetDataDelegate;
    
        private EndOperationDelegate onEndGetDataDelegate;
    
        private System.Threading.SendOrPostCallback onGetDataCompletedDelegate;
    
        public event System.EventHandler<GetDataCompletedEventArgs> GetDataCompleted;
    
        public TestingServiceClient()
        {
        }
    
        public TestingServiceClient(string endpointConfigurationName) :
            base(endpointConfigurationName)
        {
        }
    
        public TestingServiceClient(string endpointConfigurationName, string remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }
    
        public TestingServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }
    
        public TestingServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
            base(binding, remoteAddress)
        {
        }
    
        public System.Net.CookieContainer CookieContainer
        {
            get
            {
                System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
                if ((httpCookieContainerManager != null))
                {
                    return httpCookieContainerManager.CookieContainer;
                }
                else
                {
                    return null;
                }
            }
            set
            {
                System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
                if ((httpCookieContainerManager != null))
                {
                    httpCookieContainerManager.CookieContainer = value;
                }
                else
                {
                    throw new System.InvalidOperationException("Unable to set the CookieContainer. Please make sure the binding contains an HttpC" +
                            "ookieContainerBindingElement.");
                }
            }
        }
    
    
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        System.IAsyncResult ITestingService.BeginGetData(System.AsyncCallback callback, object asyncState)
        {
            return base.Channel.BeginGetData(callback, asyncState);
        }
    
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        Dictionary<string, byte[]> ITestingService.EndGetData(System.IAsyncResult result)
        {
            return base.Channel.EndGetData(result);
        }
    
        private System.IAsyncResult OnBeginGetData(object[] inValues, System.AsyncCallback callback, object asyncState)
        {
            return ((ITestingService)(this)).BeginGetData(callback, asyncState);
        }
    
        private object[] OnEndGetData(System.IAsyncResult result)
        {
            Dictionary<string, byte[]> retVal = ((ITestingService)(this)).EndGetData(result);
            return new object[] {
                        retVal};
        }
    
        private void OnGetDataCompleted(object state)
        {
            if ((this.GetDataCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.GetDataCompleted(this, new GetDataCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }
    
        public void GetDataAsync()
        {
            if ((this.onBeginGetDataDelegate == null))
            {
                this.onBeginGetDataDelegate = new BeginOperationDelegate(this.OnBeginGetData);
            }
            if ((this.onEndGetDataDelegate == null))
            {
                this.onEndGetDataDelegate = new EndOperationDelegate(this.OnEndGetData);
            }
            if ((this.onGetDataCompletedDelegate == null))
            {
                this.onGetDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetDataCompleted);
            }
    
            base.InvokeAsync(this.onBeginGetDataDelegate, null, this.onEndGetDataDelegate, this.onGetDataCompletedDelegate, null);
        }
    
        private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState)
        {
            return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
        }
    
        private object[] OnEndOpen(System.IAsyncResult result)
        {
            ((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result);
            return null;
        }
    
        private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState)
        {
            return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
        }
    
        private object[] OnEndClose(System.IAsyncResult result)
        {
            ((System.ServiceModel.ICommunicationObject)(this)).EndClose(result);
            return null;
        }
        
        protected override ITestingService CreateChannel()
        {
            return new TestingServiceClientChannel(this);
        }
    
    
        class TestingServiceClientChannel : ChannelBase<ITestingService>, ITestingService
        {
    
            public TestingServiceClientChannel(System.ServiceModel.ClientBase<ITestingService> client) :
                base(client)
            {
            }
    
            public System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState)
            {
                System.IAsyncResult _result = base.BeginInvoke("GetData", new object [0], callback, asyncState);
                return _result;
            }
    
            public Dictionary<string, byte[]> EndGetData(System.IAsyncResult result)
            {
                object[] _args = new object[0];
                Dictionary<string, byte[]> _result = (Dictionary<string, byte[]>)(base.EndInvoke("GetData", _args, result));
                return _result;
            }
        }
    }
    

    This is the config file:

    <?xml version="1.0"?>
    <configuration>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_ITestingService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" sendTimeout="00:00:60" receiveTimeout="00:00:60"/>
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestingService"
            contract="ITestingService" name="BasicHttpBinding_ITestingService" />
        </client>
      </system.serviceModel>
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

    And this is the code that does the actual connection:

    System.ServiceModel.BasicHttpBinding basicHttpBinding = new System.ServiceModel.BasicHttpBinding();
                basicHttpBinding.MaxBufferSize = int.MaxValue;
                basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
                EndpointAddress endpoint = new System.ServiceModel.EndpointAddress(this.txtIP.Text);
                testingService = new TestingServiceClient(basicHttpBinding, endpoint);
    
                testingService.GetDataCompleted += (o, arg) =>
                    {
                        try
                        {
                            if (arg == null || arg.Result == null || !Utilities.Instance.CreateModel(arg.Result))
                            {
                                MessageBox.Show("Invalid data received", "Error", MessageBoxButton.OK);
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.InnerException.Message);
                        }
                    };
                
    
                try
                {
                    testingService.GetDataAsync();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK);
                }

    Tuesday, April 29, 2014 9:36 AM

Answers

All replies

  • Hi,

    I see that you are using the windows phone 8 and you are using the following localhost address:http://localhost:22222/testingservice, then you may meet the error.

    When we create a WCF web service in Visual Studio, by default the service only accepts connections at http://localhost/. Apps that target Windows Phone OS 7.1 can connect to the development computer as localhost because the Windows Phone 7.1 emulator uses the network connection of the development computer. The Windows Phone 8 Emulator, however, configures itself as a separate device on the network. As a result, an app running on the Windows Phone 8 Emulator can’t connect to the development computer as localhost.

    To solve the connection problem caused by the localhost address, you have to configure the WCF to accept connections from other devices on the network. These devices connect to the service by using the IP address of the development computer on which the service is running.

    Also please try to check the firewall to see if it helps.

    For more information, please try to refer to the following article:
    #How to connect to a local web service from the Windows Phone 8 Emulator:
    http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580(v=vs.105).aspx .


    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, April 30, 2014 2:26 AM
    Moderator
  • Found the issue. Happened to be Windows Firewall after all :( !
    Wednesday, April 30, 2014 2:31 AM