【发布时间】:2019-06-19 15:17:26
【问题描述】:
我有使用可移植类库的 xamarin 表单项目。 在那个 PCL 中,我引用了托管在某个服务器中的 WCF 服务。
wcf 绑定是具有安全传输的 Basichttpbinding,因为 PCL 不支持 wshttpbinding。
wcf 也使用 https,我有一个有效的证书。
我想保护消息的安全,因为现在如果我在我的 android 中安装某种应用程序提琴手或打包监视器,每次调用我的服务时,我都可以看到可读格式的 xml 数据。
我认为通过使用 https 我可以保护它。 我尝试使用 wcf TransportWithMessageCredential 但它无法登录到我的服务,因为 xamarin 尚不支持此组合
所以:(经过研究我发现)
- PCL 不支持 wshttpbinding,只支持 basicHttpBinding
- Xamarin.Forms basicHttpBinding 不支持消息安全,但仅支持 仅传输凭据
还有
- Xamarin 不支持 TransportWithMessageCredential,但仅支持 传输安全,但传输安全不能保护数据免受 MITM 的侵害。
其他人如何使用 xamarin 表单并保护这些数据? 我错过了什么吗? 有什么建议?
已编辑
我正在尝试在发送到服务之前加密 xml 请求,但每次我将消息从 xml 更改为编码字符时都会失败(我猜是因为服务器无法识别架构)
我在客户端实现了 IClientMessageInspector,在服务器端也实现了 IDispatchMessageInspector。
我需要一些帮助,如何将加密的 xml 请求发送到服务器。如果我在这里这样做,那么我可以从服务端(服务器)解码它
在客户端我有以下内容
Public Function BeforeSendRequest(ByRef request As Message, channel As IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest
Dim Binding As New BasicHttpBinding(BasicHttpSecurityMode.Transport)
Dim ms As MemoryStream = New MemoryStream(System.Text.Encoding.UTF8.GetBytes(EncryptedData(request.ToString)))
Dim RQuotas As Xml.XmlDictionaryReaderQuotas = Binding.ReaderQuotas
Dim reader = Xml.XmlDictionaryReader.CreateTextReader(ms, RQuotas)
request = Message.CreateMessage(reader, Int32.MaxValue, request.Version)
Return Nothing
End Function
我不确定我是否做得正确。欢迎任何帮助。
【问题讨论】:
-
为什么不创建一个调用您的 wcf 服务的 restful webapi,然后从您的移动应用程序中使用该 webapi?
-
您关于basicHttpBinding 不支持消息安全的说法是不正确的。 (docs.microsoft.com/en-us/dotnet/framework/wcf/samples/…doc]
-
在 xamarin.Forms BasicHttpBinding 中仅支持 TransportCredentialOnly 。我会编辑它。
标签: wcf xamarin.forms portable-class-library basichttpbinding