2010-04-29 48 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