WCF错误调用Ws2007HttpBinding

时间:2012-06-05 06:58:02

标签: c# wcf wcf-wshttpbinding

我正在尝试从WCF ws2007HttpBinding服务获取数据,但每次运行时都会出现以下错误:

Content Type application/soap+xml; charset=utf-8 was not supported by service 
http://localhost/GoldInSacks.MutualFunds.local/MutualFunds.svc.  The client
and service bindings may be mismatched.

InnerException读取这个:

The remote server returned an error: (415) Cannot process the message because 
the content type 'application/soap+xml; charset=utf-8' was not the expected 
type 'text/xml; charset=utf-8'..

web.config的system.ServiceModel部分如下所示:

<system.serviceModel>
    <services>
        <service name="GoldInSacks.MutualFunds">
            <endpoint address="" 
                      binding="ws2007HttpBinding" 
                      contract="GoldInSacks.MutualFunds.Local.IMutualFunds" />
        </service>
    </services>

    <bindings>
        <ws2007HttpBinding>
            <binding>
                <security mode="None" />
            </binding>
        </ws2007HttpBinding>
    </bindings>
</system.serviceModel>

并且当前在控制台应用程序中运行的客户端代码如下所示:

        EndpointAddress address = 
            new EndpointAddress("http://localhost/MutualFunds.local/MutualFunds.svc");

        var binding = new WS2007HttpBinding();
        binding.Security.Mode = SecurityMode.None;

        ChannelFactory<IMutualFundsChannel> channelFactory = 
            new ChannelFactory<IMutualFundsChannel>(binding, address);
        IMutualFundsChannel channel = channelFactory.CreateChannel();

        var mf = channel.GetMutualFundsByCustomer(1);

        channel.Close();

        foreach (var m in mf)
        {
            System.Console.WriteLine(m.Name);
        }

        System.Console.ReadLine();

对GetMutualFundsByCustomer的调用发生错误。

我也尝试过wsHttpBinding,但它也给出了同样的错误。

有人知道如何使这项工作吗?

(我为这个问题的简洁而道歉,但现在已经很晚了,我需要睡觉了。)

1 个答案:

答案 0 :(得分:1)

您是否在客户端和服务端使用相同的SOAP版本?也许相关? http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f29cd9c8-3c89-43d2-92ae-d2a270ab86b9/

干杯 --Jocke