ChannelFactory<T>
में वर्चुअल विधि CreateChannel()
है। यदि यह ओवरराइड नहीं है, तो यह गतिशील कोड पीढ़ी का उपयोग करता है, जो मोनो टच पर विफल रहता है।
समाधान इसे ओवरराइड करना और अपना स्वयं का संकलन-समय कार्यान्वयन प्रदान करना है।
नीचे मेरा एक पुराना सेवा कार्यान्वयन है जो कम से कम मोनो टच पर काम करने के लिए उपयोग किया जाता है। मैंने इसे 2 आंशिक कक्षाओं में विभाजित किया - पहला निर्माण सभी बिल्डों में जोड़ा जा रहा है, दूसरा आईओएस बनाता है (गतिशील पीढ़ी तंत्र को अभी भी विंडोज़ पर काम करने की इजाजत देता है)।
मैंने इसे केवल 1 सेवा कॉल में शामिल कर दिया है।
TransactionService.cs:
public partial class TransactionService : ClientBase<IConsumerService>, IConsumerService
{
public TransactionService()
{
}
public TransactionService(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public TransactionService(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public TransactionService(string endpointConfigurationName, EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public TransactionService(Binding binding, EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public AccountBalanceResponse GetAccountBalance(AccountBalanceQuery query)
{
return Channel.GetAccountBalance(query);
}
}
TransactionService.iOS.cs: ConsumerServiceClientChannel
जो प्रतिबिंब के माध्यम से कॉल)
public partial class TransactionService
{
protected override IConsumerService CreateChannel()
{
return new ConsumerServiceClientChannel(this);
}
private class ConsumerServiceClientChannel : ChannelBase<IConsumerService>, IConsumerService
{
public ConsumerServiceClientChannel(System.ServiceModel.ClientBase<IConsumerService> client) :
base(client)
{
}
// Sync version
public AccountBalanceResponse GetAccountBalance(AccountBalanceQuery query)
{
object[] _args = new object[1];
_args[0] = query;
return (AccountBalanceResponse)base.Invoke("GetAccountBalance", _args);
}
// Async version
public IAsyncResult BeginGetAccountBalance(AccountBalanceQuery query, AsyncCallback callback, object asyncState)
{
object[] _args = new object[1];
_args[0] = query;
return (IAsyncResult)base.BeginInvoke("GetAccountBalance", _args, callback, asyncState);
}
public AccountBalanceResponse EndGetAccountBalance(IAsyncResult asyncResult)
{
object[] _args = new object[0];
return (AccountBalanceResponse)base.EndInvoke("GetAccountBalance", _args, asyncResult);
}
}
}
संपादित करें निष्पादित करता है: मैं बस नवीनतम के साथ इस परीक्षण किया मीट्रिक टन (5.2) - अब मुझे उस अतिरिक्त बॉयलर प्लेट की आवश्यकता नहीं है, जो पहले वहां थी, केवल CreateChannel() ओवरराइड करें। मैंने मिलान करने के लिए नमूना कोड साफ़ कर लिया है।
EDIT2: मैंने एक एसिंक विधि कार्यान्वयन जोड़ा।
आपके साझाकरण के लिए धन्यवाद, मैं इसे आजमाएं। – BlueSky
आपका समाधान सफल है, धन्यवाद। – BlueSky
यहां यह कहता है कि यह क्लास चैनलबेस नहीं ढूंढ सकता है। और मैं नहीं देखता कि मैं इसका उपयोग एसिंक्रोनस विधियों के साथ कैसे कर सकता हूं। धन्यवाद! – cheeesus