views:

64

answers:

1

Hi All,

I'm trying to figure out how to call a WCF service from a windows smart phone. I have a very simple smartphone console app, which does nothing but launch and make 1 call to the service. The service simply returns a string. I am able to instantiate the proxy class but when i call the method it throws an exception:

There was no endpoint listening at http://mypcname/Service1.svc/basic that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The inner exception:

Could not establish connection to network.

I've tried to follow this tutorial on setting up services with windows mobile.

I've used the NetCFSvcUtil to create the proxy classes. I have the service running on IIS on my machine and had the Util consume the wsdl from that location. I've created a basic http binding as suggested in the article and i think i've pointed the proxy at the correct uri.

Here some sections of relevant code in case it's helpful to see. If anyone has any suggestions, i'd really appreciate it. I'm not sure what else i can poke at to get this thing to work.

Thanks!

Client, (Program.cs):

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace WcfPoC
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Service1Client proxy = new Service1Client();
                string test = proxy.GetData(5);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.InnerException.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
    }
}

Client Proxy excerpt (Service1.cs):

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class Service1Client : Microsoft.Tools.ServiceModel.CFClientBase<IService1>, IService1
{
    //modified according to the walk thru linked above...
    public static System.ServiceModel.EndpointAddress EndpointAddress = new System.ServiceModel.EndpointAddress("http://boston7/Service1.svc/basic");

    /*
     *a bunch of code create by the svc util - left unmodified
     */
}

The Service (Service1.svc.cs):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService1
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
    public class Service1 : IService1
    {
        public string GetData(int value)  //i'm calling this one...
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}

Service Interface (IService1.cs):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService1
{
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
[ServiceContract]
public interface IService1
{

    [OperationContract]
    string GetData(int value);  //this is the call im using...

    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);

    // TODO: Add your service operations here
}


// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
    /*
     * ommitted - not using this type anyway...
     */
}

}

Web.config excerpt:

    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://boston7/" />
            </baseAddresses>
          </host>
      </service>
    </services>
+1  A: 

I think your problem is because in IIS endpoint addresses are always considered to be relative to the address of the .svc file that represents the service.

You have used an empty address in your basicHttp endpoint, so this will resolve only the path of the .svc file.

I would suggest two things. Since you are hosting on IIS, add "basic" as the address for your basicHttpBinding and remove the host base address, this is redundant.

Per MSDN: You must always use relative endpoint addresses for IIS-hosted service endpoints. Supplying a fully-qualified endpoint address (for example, http://localhost/MyService.svc) can lead to errors in the deployment of the service if the endpoint address does not point to the IIS-application that hosts the service exposing the endpoint. Using relative endpoint addresses for hosted services avoids these potential conflicts

RandomNoob
Thanks but it didn't work... Same error.
sweeney
Are you supposed to be able to hit this address in the browser?http://boston7/Service1.svc/basicI am able to hit http://boston7/Service1.svc and http://boston7/Service1.svc?wsdl after making your suggested changes but /basic does not resolve. Anything else i might try?
sweeney
is the client still throwing the same exception?
RandomNoob
It is...however i've discovered that the internet connection on the device may have been the culprit. I'm going to leave this open for now since i have a feeling that this issue may have more to it than just the connection, but we'll see. Thanks for following up!
sweeney