我想弄清楚如何从Windows智能手机中调用WCF服务。我有一个非常简单的智能手机控制台应用程序,除了启动和打电话给服务外,什么都不做。该服务只是返回一个字符串。我能够实例化代理类,但是当我调用该方法,它抛出一个异常:不能使用Windows Mobile 5的WCF服务:找不到端点
有没有终点在 http://mypcname/Service1.svc/basic听那个 可以接受的消息。这通常是由不正确的地址 或SOAP操作导致的 。有关更多详细信息,请参见InnerException,如果存在 。
内部异常:
无法建立连接 网络。
我试着按照this教程来设置windows mobile的服务。
我已经使用NetCFSvcUtil来创建代理类。我在我的机器上的IIS上运行该服务,并让该Util使用该位置的wsdl。我已经创建了一篇基本的http绑定,正如文章中所建议的,我想我已经指出了正确的uri代理。
这里有一些相关的代码段,以防万一它有助于看到。如果有人有任何建议,我会很感激。我不知道还有什么我可以戳到让这个东西工作。
谢谢!
客户端,(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);
}
}
}
}
客户端代理摘录(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
*/
}
的服务(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;
}
}
}
服务接口(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文件摘录:
<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>
嘿,布赖恩,你有没有得到WCF在这些工作:审查:移动设备? – jp2code 2013-04-12 20:27:54