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>