Обратите внимание, что есть случаи, когда вы определили свой собственный пользовательский класс и хотите сохранить атрибуты, тогда вы должны использовать copy.copy()
или copy.deepcopy()
, а не альтернативы, например, в Python 3:
import copy
class MyList(list):
pass
lst = MyList([1,2,3])
lst.name = 'custom list'
d = {
'original': lst,
'slicecopy' : lst[:],
'lstcopy' : lst.copy(),
'copycopy': copy.copy(lst),
'deepcopy': copy.deepcopy(lst)
}
for k,v in d.items():
print('lst: {}'.format(k), end=', ')
try:
name = v.name
except AttributeError:
name = 'NA'
print('name: {}'.format(name))
Выходы:
lst: original, name: custom list
lst: slicecopy, name: NA
lst: lstcopy, name: NA
lst: copycopy, name: custom list
lst: deepcopy, name: custom list
Вот простой фрагмент кода, который можно использовать в качестве руководства:
//first at the class level, create a private variable for the client.
private Service1Client _client;
private Button _addButon;
private TextView _txtDeptName;
//Initialize the _client in the OnCreate() method.
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var endpoint = new EndpointAddress("http://<ipAddress:port>/Service1.svc");
var binding = new BasicHttpBinding{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
TimeSpan timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
_client = new Service1Client(binding, endpoint);
_client.AddDeptCompleted += ClientAddDeptCompleted;
_addButton = FindViewById<Button>(Android.Resources.Id.Add);
_addbutton.Click += AddButton_Clicked;
_txtDeptName = FindViewbyId<TextView>(Android.Resources.Id.Name);
}
//Then within the event handlers, do something like this
public void AddButton_Clicked(object sender, EventArgs e)
{
_client.AddDeptAsync(_txtDeptName.Text);
}
//Handle the request completed event.
private void ClientAddDeptCompleted(object sender, AddDeptCompletedEventArgs addDeptCompletedEventArgs)
{
//TODO: Something with the notification that the request has completed.
}
Вы также должны следовать аналогичному шаблону для других кнопок и служебных вызовов. Прошу прощения, если я сделал некоторые опечатки. Я перехожу из немного памяти и некоторых инструкций WCF на сайт Xamarin.
Сначала вы должны добавить сервис в свой проект. Вы можете сделать это, используя следующую команду:
Cd C: \ Program Files (x86) \ Microsoft SDK \ Silverlight \ v5.0 \ Инструменты \ SlSvcUtil.exe http: // localhost: 2323 / HisDashboardService / ProfilerService.svc / directory: "C: \ Folder"
blockquote>Затем добавьте проект созданный файл Чтобы использовать добавленную услугу, необходимо выполнить следующую процедуру
public class ServiceAccessor { static string serviceUrl = "http://172.16.12.17:7698/HisDashboardService/"; public static readonly EndpointAddress ProfilerServiceEndPoint = new EndpointAddress(serviceUrl + "ProfilerService.svc"); private ProfilerServiceClient _profilerServiceClient; private static ServiceAccessor _instanceServiceAccessor; public static ServiceAccessor Instance { get { return _instanceServiceAccessor ?? (_instanceServiceAccessor = new ServiceAccessor()); } } ServiceAccessor() { InitializeServiceClient(); } private void InitializeServiceClient() { BasicHttpBinding binding = CreateBasicHttp(); #region ProfilerService _profilerServiceClient = new ProfilerServiceClient(binding, ProfilerServiceEndPoint); #endregion ProfilerService } private static BasicHttpBinding CreateBasicHttp() { BasicHttpBinding binding = new BasicHttpBinding { Name = "basicHttpBinding", MaxBufferSize = 2147483647, MaxReceivedMessageSize = 2147483647 }; TimeSpan timeout = new TimeSpan(1, 0, 0); binding.SendTimeout = timeout; binding.OpenTimeout = timeout; binding.ReceiveTimeout = timeout; return binding; } }