繁体   English   中英

Windows Phone-WCF-错误没有端点监听

[英]Windows Phone - WCF- Error There was no endpoint listening at

尝试构建项目时出现错误。 在我的项目中,当客户将电话号码发送到服务时,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;
        }
}

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

我认为这取决于什么是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>

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

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

感谢所有阅读和回答我的问题。 我已经解决了。问题出在lbl_Profile(这是数据库中的表)。 我不明白为什么它不起作用,但是当我使用List <string>替换lbl_Profile时,它运行良好。

诚信服务

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;

}

内部客户

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM