Windows Phone - WCF-错误没有端点正在侦听

时间:2012-03-30 05:16:23

标签: c# visual-studio windows-phone-7 wcf-data-services

尝试构建项目时出错。在我的项目中,当客户端向服务发送电话号码时,serivce将返回用户拥有此电话号码的所有信息。

这是服务

      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;
        }
}

网络服务中的配置

  <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

3 个答案:

答案 0 :(得分:1)

我认为这取决于localhost以及您当时使用的设备。

在您的开发计算机上,localhost是开发计算机。在电话上是电话。在开发机器上调试手机应用程序时,localhost仍然是手机(但令人困惑)。

尝试在开发过程中更改为使用IP地址。例如192.168.1.1(或您的开发PC正在使用的任何内容)。您可以在开发机器上使用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>

答案 1 :(得分:0)

似乎你指的是一个尚未生效的网址。尝试使用本地服务或部署在公共空间/域上的服务。

当我开始将它指向本地环境时,我遇到了同样的问题并得到了解决。

答案 2 :(得分:0)

感谢所有人阅读和回答我的问题。我刚修好了。问题出在lbl_Profile(它是数据库中的一个表)。我不明白为什么它不起作用,但是当我使用List&lt;串GT;为了取代lbl_Profile,它运作良好。

int service

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 client

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];
    }