我正在为想要通过 Web 服务连接到 Microsoft CRM 2011 的 Windows 7 Phone 制作应用程序。
我之前创建了一个控制台应用程序,并且能够让它毫无问题地发送数据。不过,让它在手机上工作要困难得多。经过多次故障排除后,我发现问题出在我使用手机的绑定中。看来我需要一个SymmetricSecurityBindingElement,这在 Windows 手机上不可用。有没有办法不需要这个元素或解决方法?
编辑
这是我对控制台应用程序的绑定,它工作正常。
BindingElementCollection bindingElements = new BindingElementCollection();
SymmetricSecurityBindingElement security = new SymmetricSecurityBindingElement();
security.IncludeTimestamp = true;
security.ProtectionTokenParameters = new SspiSecurityTokenParameters();
bindingElements.Add(security);
bindingElements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, System.Text.Encoding.UTF8));
HttpTransportBindingElement transport = new HttpTransportBindingElement();
transport.MaxBufferSize = Int32.MaxValue;
transport.MaxReceivedMessageSize = Int32.MaxValue;
bindingElements.Add(transport);
CustomBinding binding = new System.ServiceModel.Channels.CustomBinding(bindingElements);
binding.Name = "CustomBinding_IDiscoveryService";
return binding;
这是我对 windows phone 的绑定。它抛出MessageSecurityException。
BindingElementCollection phoneBindingElements = new BindingElementCollection();
TransportSecurityBindingElement security = new TransportSecurityBindingElement();
security.IncludeTimestamp = true;
phoneBindingElements.Add(security);
phoneBindingElements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, System.Text.Encoding.UTF8));
HttpTransportBindingElement transport = new HttpTransportBindingElement();
transport.MaxBufferSize = Int32.MaxValue;
transport.MaxReceivedMessageSize = Int32.MaxValue;
phoneBindingElements.Add(transport);
CustomBinding binding = new System.ServiceModel.Channels.CustomBinding(phoneBindingElements);
binding.Name = "CustomBinding_IDiscoveryService";