C# Windows Phone-WCF-错误在侦听时没有终结点
我在尝试构建项目时出错。在我的项目中,当客户端向服务发送电话号码时,serivce将返回用户拥有该电话号码的所有信息 这是服务C# Windows Phone-WCF-错误在侦听时没有终结点,c#,visual-studio,windows-phone-7,wcf-data-services,C#,Visual Studio,Windows Phone 7,Wcf Data Services,我在尝试构建项目时出错。在我的项目中,当客户端向服务发送电话号码时,serivce将返回用户拥有该电话号码的所有信息 这是服务 namespace ICService { public class ProfileService : IProfileService { public lbl_Profile ViewProfile(int phonenumber) { Profileview profile = ne
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;
}
}
公共部分类配置文件:PhoneApplicationPage
{
公众简介()
{
初始化组件();
ProfileServiceClient profileClient=新的ProfileServiceClient();
profileClient.ViewProfileCompleted+=新事件处理程序(profileService_ViewProfileCompleted);
ViewProfileAsync(电话号码);
}
void profileService_ViewProfileCompleted已完成(对象发送者,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>
这是一个错误
似乎您指向的是一个尚未激活的url。尝试使用本地服务或部署在公共空间/域上的服务
当我开始将它指向本地环境时,我也遇到了同样的问题并得到了解决。我认为这取决于什么是本地主机以及您当时使用的设备 在开发机器上,localhost是开发机器。在电话上是电话。在开发机器上调试phone应用程序时,localhost仍然是电话(无论多么令人困惑) 尝试在开发过程中更改为使用IP地址。e、 g.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_配置文件中(它是数据库中的一个表)。我不明白为什么它不起作用,但当我使用List替换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;
}
公共列表配置文件(int phonenumber)
{
ToPiDataContext db=新的ToPiDataContext();
var query=(来自db.lbl\u账户中的m)
从db.lbl\u配置文件中的n开始
其中m.AccountID==n.AccountID&&m.Phonenumber==Phonenumber
选择新的
{
n、 帐户ID
}).First();
var profile=(从db.lbl\u profile中的m开始)
其中m.AccountID==query.AccountID
选择m.First();
List lst=新列表();
第一次添加(个人资料名);
lst.Add(profile.LastName);
第一次添加(配置文件位置);
第一次添加(配置文件类型);
返回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];
}
void Profile\u加载(对象发送器,路由目标)
{
int query=(来自localaccount.account中的m)
选择m.PhoneNumber).First();
ProfileServiceClient profileClient=新的ProfileServiceClient();
profileClient.profileCompleted+=新的事件处理程序(profileClient\u profileCompleted);
profileClient.profileAsync(查询);
}
void profileClient_profileCompleted(对象发送方,profileCompletedEventArgs e)
{
txtFirstName.Text=e.Result[0];
txtLastName.Text=e.Result[1];
txtLocation.Text=e.Result[2];
txbGenre.Text=e.Result[3];
}
显示配置!!大部分相关的WCF内容都是在配置中定义的,
部分中的任何内容,无论是在服务器上还是在客户端,如果没有它,我们就无法提供帮助。谢谢,我在帖子中编辑。你能帮我解决这个问题吗?@Shailesh谢谢你的回答:)但这项服务已经上线了。我在网络浏览器上查过了。我真的不明白你的想法。你能告诉我更多的细节吗?这个项目有另一个服务名称AccountService。它在用户登录或注册时返回信息。它确实有效。但是此配置文件服务不起作用???您确定此配置文件服务在您的配置文件中具有有效的URL吗?在如果没有,试试@4u。安:当然,你可以在帖子上看到。这项服务真的很有效@gbanfill:我试过了,但还是不起作用。我保留了ProfileService并更改了其中的所有代码以返回另一个值,然后它就工作了。所以我认为地址不是问题。