1

我正在尝试从 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 但它给出了同样的错误。

有谁知道如何使这项工作?

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

4

1 回答 1

1

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

干杯——乔克

于 2012-06-05T08:55:07.867 回答