I am having an error when try to build the project. In my project, when the client send phone number to the service, serivce will return all infomation of user has this phone number.
this is service
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;
}
}
}
}
in the client
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;
}
}
the config in web service
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
in the phone
<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>
I think this is down to what is localhost and which device you are on at the time.
On your development machine localhost is the development machine. On the phone it is the phone. When debugging the phone phone application on the development machine localhost is still the phone (however confusing that is).
Try changing to using IP addreses during development. eg 192.168.1.1 (or whatever your development PC is using). You can look this up using ipconfig on your dev machine.
Edit:
Change your config file to look like
<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>
Seems you are pointing to a url that is not live yet. Try to use your local service or a service that is deployed on public space / domain.
I had same problem and got resolved when I started pointing it to local environment.
Thanks all for reading and answering my questions. I've just fixed it.The problem is in lbl_Profile(it is a table on database). I don't understand why it didn't work, but when I used List < string> to replaced lbl_Profile, it worked well.
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];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.