2012-03-30 44 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]; 
    }