2010-04-29 51 views
1

我想弄清楚如何从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> 
+0

嘿,布赖恩,你有没有得到WCF在这些工作:审查:移动设备? – jp2code 2013-04-12 20:27:54

回答

1

我觉得你的问题是因为在IIS端点地址总是被认为是相对于代表服务的.svc文件的地址。

您在basicHttp端点中使用了空白地址,因此这只会解析.svc文件的路径。

我会建议两件事。由于您在IIS上托管,因此添加“basic”作为basicHttpBinding的地址并删除主机基址,这是多余的。

每个MSDN:您必须始终使用IIS托管的服务端点的相对端点地址。如果端点地址未指向承载暴露端点的服务的IIS应用程序,则提供完全限定的端点地址(例如http://localhost/MyService.svc)可能会导致部署服务时出错。使用托管服务的相对端点地址避免了这些潜在的冲突

+0

谢谢,但它没有工作...相同的错误。 – 2010-04-29 19:22:37

+0

你应该能够在浏览器中打开这个地址吗? http://boston7/Service1.svc/basic 在进行建议的更改后,我可以点击http://boston7/Service1.svc和http://boston7/Service1.svc?wsdl,但/ basic不能解决。还有什么我可以尝试? – 2010-04-29 19:33:55

+0

客户端仍然抛出相同的异常? – kd7 2010-04-30 20:00:20