我正在尝试从 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 但它给出了同样的错误。
有谁知道如何使这项工作?
(我为这个问题的简洁性道歉,但已经很晚了,我需要睡觉)。