使此WCF客户端代码在Mac上的Mono和MonoTouch上工作? [英] Make this WCF client code work on Mono and MonoTouch on the Mac?

查看:154
本文介绍了使此WCF客户端代码在Mac上的Mono和MonoTouch上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使以下代码在Mono控制台应用程序中工作,并成为MonoTouch应用程序的最终目标.使用Windows控制台应用程序,该代码在VS2008下可以正常工作. 在Mac上将其作为Mono控制台应用程序运行时,我得到

I am trying to get the following piece of code to work in a Mono console app and as the ultimate goal in a MonoTouch application. The code works fine under VS2008 using a Windows console app. When running it as a Mono console app on the Mac, I get

未处理的异常:System.NotImplementedException:请求的 功能未实现.在 System.ServiceModel.Channels.SecurityBindingElement.CanBuildChannelFactory [IDuplexChannel] (System.ServiceModel.Channels.BindingContext上下文)在[0x00000]中 :0

Unhandled Exception: System.NotImplementedException: The requested feature is not implemented. at System.ServiceModel.Channels.SecurityBindingElement.CanBuildChannelFactory[IDuplexChannel] (System.ServiceModel.Channels.BindingContext context) [0x00000] in :0

在MonoTouch中,我收到此错误:

In MonoTouch, I receive this error:

未处理的异常:System.ServiceModel.FaultException:错误 验证邮件的安全性时发生.在 System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object []参数)在[0x00188]中 /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:545

Unhandled Exception: System.ServiceModel.FaultException: An error occurred when verifying security for the message. at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x00188] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:545

有人可以eplxain出什么问题了吗?没有涉及使事情变得简单的app.config.

Can somebody eplxain what is wrong? There is no app.config involved to keep things simple.

using System;
using MonoAPI3.BLAPI3Session;
using Brainloop.ServiceLibrary.DataModel;
using System.ComponentModel;
using System.ServiceModel;

public static void Main()
{
System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { return true; };

var oClient = new SessionServiceClient( new BasicHttpBinding( BasicHttpSecurityMode.TransportWithMessageCredential )
            {
                CloseTimeout = new TimeSpan( 0, 0, 10 ),
                OpenTimeout = new TimeSpan( 0, 1, 0 ),
                ReceiveTimeout = new TimeSpan( 0, 1, 0 ),
                SendTimeout = new TimeSpan( 0, 1, 0 ),
                AllowCookies = false,
                BypassProxyOnLocal = false,
                HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                MaxBufferSize = 65536,
                MaxBufferPoolSize = 524288,
                MaxReceivedMessageSize = 65536,
                MessageEncoding = WSMessageEncoding.Text,
                TextEncoding = System.Text.Encoding.UTF8,
                TransferMode = TransferMode.Buffered,
                UseDefaultWebProxy = true,
                ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
                {
                    MaxDepth = 32,
                    MaxStringContentLength = 8192,
                    MaxArrayLength = 16384,
                    MaxBytesPerRead = 4096,
                    MaxNameTableCharCount = 16384
                }

            },
            new EndpointAddress( "https://service.myserver.com/Service/V3/Session.svc" ) );

            oClient.ClientCredentials.UserName.UserName = "user@domain.com";
            oClient.ClientCredentials.UserName.Password = "pwd";

            SessionInfo oInfo = oClient.StartSession();

            Console.WriteLine( "SESSION HASH: " + oInfo.SessionHash );
}

推荐答案

问题所在的代码行是:

BasicHttpSecurityMode.TransportWithMessageCredential

Mono不支持WS-Security.基本上,BasicHttpSecurityMode上有很多选项无法使用.如果您需要消息凭证,那么恐怕此代码无法正常工作.这是一个相关的链接:

Mono does not support WS-Security. Basically there are many options on BasicHttpSecurityMode which will not work. If you require Message Credentials, then I'm afraid this code cannot be made to work. Here is a related link:

http://lists.ximian.com/pipermail/mono-bugs/2010-January/096972.html

这篇关于使此WCF客户端代码在Mac上的Mono和MonoTouch上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆