【发布时间】:2019-01-15 11:58:39
【问题描述】:
大家好!
我有一个问题:我有 WCF 服务。我还有一个连接到服务器的 Xamarin.Forms 应用程序。
我第一次使用 slsvcutil.exe,但该解决方案似乎不太合适,它是基于事件构建的,因为有很多事件并且代码难以阅读。
当我尝试通过 ChannelFactory 进行操作时,它适用于 Android。现在Android没有问题,但对于iOS,由于CreateChannel()方法,它根本无法工作。我使用这些链接在 ChannelBase 上做了另一堂课:
并且错误消失。但它只是没有连接到我的 WCF 服务...... 尝试连接了几天,但仍然没有... 也许有机会以另一种方式做到这一点? 任何帮助将不胜感激。
附言我的 iOS 接口和类的代码:
public class NewClassForConnectionIOS : ClientBase<IAis7MobileIssoSServerCoreXamarin>, IAis7MobileIssoSServerCoreXamarin
{
public NewClassForConnectionIOS() : base() { }
public NewClassForConnectionIOS(Binding binding, EndpointAddress endpointAddress) : base(binding, endpointAddress) { }
public NewClassForConnectionIOS(string endpoint) : base(endpoint) { }
public string[] HttpsGetSessionIdForIssoS(string user, string pass)
{
return ((NewClassForConnectionChannel)base.Channel).HttpsGetSessionIdForIssoS(user, pass);
}
public IAis7MobileIssoSServerCoreXamarin CreateConnection()
{
return CreateChannel();
}
protected override IAis7MobileIssoSServerCoreXamarin CreateChannel()
{
return new NewClassForConnectionChannel(this);
}
private class NewClassForConnectionChannel : ChannelBase<IAis7MobileIssoSServerCoreXamarin>, IAis7MobileIssoSServerCoreXamarin
{
public NewClassForConnectionChannel(ClientBase<IAis7MobileIssoSServerCoreXamarin> client) : base(client) { }
public string[] HttpsGetSessionIdForIssoS(string user, string pass)
{
return (string[])base.Invoke("HttpsGetSessionIdForIssoS", new object[] { user, pass });
}
//public IAsyncResult BeginHttpsGetSessionIdForIssoS(string user, string pass, AsyncCallback callback, object asyncState)
//{
// object[] _args = new object[2];
// _args[0] = user;
// _args[1] = pass;
// return (IAsyncResult)base.BeginInvoke("HttpsGetSessionIdForIssoS", _args, callback, asyncState);
//}
//public string[] EndHttpsGetSessionIdForIssoS(IAsyncResult asyncResult)
//{
// object[] _args = new object[0];
// return (string[])base.EndInvoke("HttpsGetSessionIdForIssoS", _args, asyncResult);
//}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName ="IAis7MobileIssoSServerCoreXamarin")]
public interface IAis7MobileIssoSServerCoreXamarin
{
[System.ServiceModel.OperationContractAttribute(Action = "HttpsGetSessionIdForIssoS", ReplyAction = "http://tempuri.org/IAis7MobileIssoSServerCoreXamarin/HttpsGetSessionIdForIssoSResponse")]
string[] HttpsGetSessionIdForIssoS(string user, string pass);
}
【问题讨论】:
-
嗨@Денис Чорный !我在这里有同样的情况,但我得到 ChannelBase 不包含 Invoke 的定义!您是否在上一个版本中遇到该错误?谢谢!
-
你好@Ignacio!不,我没有。如您所见,上述问题是一个可行的解决方案。现在我有一个单独的 iOS 类,它继承自
clientBase类并包含一个继承自ChannelBase的类,就像上面的代码一样。 -
你好@Денис Чорный!我正在使用 .Net Standard 2.0,这就是 Invoke (...) 不可用的原因。我所做的(对于处于相同情况的其他人)是在 Visual Studio 15.8.1 版本中使用 svcutil 重新生成连接服务参考文件,使用此命令 svcutil /async /tcv:Version35 https://... 然后使用这个关于同步方法: var iar = BeginInvoke("YourMethod", _args, null, null); return (string)EndInvoke("YourMethod", Array.Empty
标签: c# wcf xamarin.forms xamarin.ios channelfactory