Windows Phone - WCF- Ошибка Не было прослушивания конечной точки на - PullRequest
0 голосов
/ 30 марта 2012

У меня ошибка при попытке собрать проект. В моем проекте, когда клиент отправляет номер телефона в сервис, 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 ]

1 голос
/ 30 марта 2012

Я думаю, это связано с тем, что является localhost и какое устройство вы используете в данный момент.

На вашей машине разработки localhost - машина разработки. На телефоне это телефон. При отладке приложения телефона на компьютере разработчика локальный хост по-прежнему остается телефоном (хотя и сбивает с толку).

Попробуйте перейти на использование IP-адресов во время разработки. например 192.168.1.1 (или то, что использует ваш компьютер для разработки). Вы можете посмотреть это с помощью ipconfig на вашем компьютере разработчика.

Edit:

Измените ваш конфигурационный файл, чтобы он выглядел как

<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 голосов
/ 30 марта 2012

Спасибо всем за чтение и ответы на мои вопросы.Я только что исправил. Проблема в lbl_Profile (это таблица в базе данных).Я не понимаю, почему это не сработало, но когда я использовал List для замены 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];
    }
0 голосов
/ 30 марта 2012

Кажется, вы указываете на URL, который еще не активирован. Попробуйте использовать локальную службу или службу, развернутую в публичном пространстве / домене.

У меня была та же проблема, и я был решен, когда начал указывать ее на локальную среду.

...