2012-03-30 40 views
0

沒有端點偵聽當我嘗試構建項目時出現錯誤。在我的項目中,當客戶端向服務發送電話號碼時,服務器將返回用戶擁有此電話號碼的所有信息。Windows Phone - WCF-錯誤在

這是服務

 namespace ICService 
{ 
    public class ProfileService : IProfileService 
    { 
     public lbl_Profile ViewProfile(int phonenumber) 
     { 
      Profileview profile = new Profileview(); 
      return profile.ViewProfile(phonenumber); 
     } 
    } 

    public class Profileview 
    { 
     public lbl_Profile ViewProfile(int phonenumber) 
     { 
      try 
      { 
       ToPiDataContext db = new ToPiDataContext(); 
       var query = (from m in db.lbl_Accounts 
          from n in db.lbl_Profiles 
          where m.AccountID == n.AccountID && m.Phonenumber == phonenumber 
          select new 
          { 
           n.AccountID 
          }).First(); 

       var profile = (from m in db.lbl_Profiles 
           where m.AccountID == query.AccountID 
           select m).First(); 
       return profile; 
      } 
      catch 
      { 
       return null; 
      } 
     } 
    } 
} 

在客戶端

public partial class Profile : PhoneApplicationPage 
    { 
public Profile() 
{ 
       InitializeComponent(); 
        ProfileServiceClient profileClient = new ProfileServiceClient(); 
       profileClient.ViewProfileCompleted += new EventHandler<ViewProfileCompletedEventArgs>(profileService_ViewProfileCompleted); 
       profileClient.ViewProfileAsync(phonenumber); 
} 

     void profileService_ViewProfileCompleted(object sender, ViewProfileCompletedEventArgs e) 
     { 
       txbFirstName.Text = e.Result.FirstName; 
       txbLastName.Text = e.Result.LastName; 
       txbLocation.Text = e.Result.Location; 
       txbGenre.Text = e.Result.Genre; 
     } 
} 

在手機的配置在Web服務

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IAccountService" maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
       <security mode="None" /> 
      </binding> 
      <binding name="BasicHttpBinding_IProfileService" maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
       <security mode="None" /> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:2183/AccountService.svc" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAccountService" 
      contract="AccountService.IAccountService" name="BasicHttpBinding_IAccountService" /> 
     <endpoint address="http://localhost:2183/ProfileService.svc" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProfileService" 
      contract="ProfileService.IProfileService" name="BasicHttpBinding_IProfileService" /> 
    </client> 
</system.serviceModel> 

並且這是錯誤 http://i915.photobucket.com/albums/ac358/thewall_trancong/Untitled-14.png

+1

**向我們展示CONFIG!**大部分相關WCF的東西是在配置定義 - 什麼裏面的''部分 - 無論是在服務器還是客戶端 - 沒有它,我們不可能幫助 – 2012-03-30 05:26:26

+1

謝謝,我在我的文章上編輯過。你能幫我解決這個問題嗎? – 2012-03-30 09:38:11

回答

0

似乎您指向的是還沒有生效的網址。嘗試使用您的本地服務或部署在公共空間/域中的服務。

當我開始將它指向本地環境時,我遇到了同樣的問題並得到解決。

+0

@ Shailesh感謝回答:)但服務已經生效。我在網頁瀏覽器上檢查過它。 http://i915.photobucket.com/albums/ac358/thewall_trancong/Untitled-15.png – 2012-03-30 06:12:49

1

我認爲這是根據什麼是本地主機以及當時的設備。

在您的開發機器localhost是開發機器。在電話上,這是電話。在開發機器上調試電話手機應用程序時,localhost仍然是電話(但是令人困惑的是)。

嘗試在開發過程中更改爲使用IP地址。例如192.168.1.1(或任何您的個人電腦正在使用的開發)。你可以在你的開發機器上使用ipconfig來查看它。

編輯:

更改您的配置文件看起來像

<client> 
    <endpoint address="http://192.168.1.1:2183/AccountService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAccountService" 
     contract="AccountService.IAccountService" name="BasicHttpBinding_IAccountService" /> 
    <endpoint address="http://192.168.1.1:2183/ProfileService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProfileService" 
     contract="ProfileService.IProfileService" name="BasicHttpBinding_IProfileService" /> 
</client> 
+0

我真的不明白你的想法。你能告訴我更多細節嗎? – 2012-03-30 10:08:34

+0

該項目有另一個服務名稱AccountService。它在用戶登錄或註冊時返回信息。真的行。但是這個配置文件服務不起作用? – 2012-03-30 10:44:49

+0

您確定此配置文件服務在配置文件中有有效的URL嗎?在** 」...> **。如果沒有,請嘗試 – 2012-03-30 10:57:41

0

感謝所有的閱讀和回答我的問題。我剛解決它。問題在於lbl_Profile(它是一個數據庫表)。我不明白爲什麼它不起作用,但是當我用List> < string>替換lbl_Profile時,它運行良好。

INT業務

public List<string> profile(int phonenumber) 
{ 
    ToPiDataContext db = new ToPiDataContext(); 
    var query = (from m in db.lbl_Accounts 
       from n in db.lbl_Profiles 
       where m.AccountID == n.AccountID && m.Phonenumber == phonenumber 
       select new 
       { 
        n.AccountID 
       }).First(); 

    var profile = (from m in db.lbl_Profiles 
        where m.AccountID == query.AccountID 
        select m).First(); 
    List<string> lst = new List<string>(); 
    lst.Add(profile.FirstName); 
    lst.Add(profile.LastName); 
    lst.Add(profile.Location); 
    lst.Add(profile.Genre); 
    return lst; 

} 

INT客戶

void Profile_Loaded(object sender, RoutedEventArgs e) 
     { 
       int query = (from m in localaccount.account 
          select m.PhoneNumber).First(); 
       ProfileServiceClient profileClient = new ProfileServiceClient(); 
       profileClient.profileCompleted += new EventHandler<profileCompletedEventArgs>(profileClient_profileCompleted); 
       profileClient.profileAsync(query); 
      } 

    void profileClient_profileCompleted(object sender, profileCompletedEventArgs e) 
    { 
     txtFirstName.Text = e.Result[0]; 
     txtLastName.Text = e.Result[1]; 
     txtLocation.Text = e.Result[2]; 
     txbGenre.Text = e.Result[3]; 
    }