WCF IIS 寄宿问题

在客户端不使用配置文件,通过写代码的方式调用寄宿在IIS上Wcf服务的时候,出现一个比较奇怪的问题。

客户端的代码如下:

Binding httpBinding = new BasicHttpBinding();
EndpointAddress httpAddressIISHost = new EndpointAddress("http://localhost/wcfservices/CalculatorService.svc");
using (Client iisClient = new Client(httpBinding, httpAddressIISHost))
            {
                try
                {
                    Console.WriteLine("begin invocate calculator service via http transport");
                    Console.WriteLine("x + y = {0} where x = {1} and y = {2}", iisClient.Add(1, 3), 1, 3);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    Console.ReadLine();
                }
            }

 服务端配置文件如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="metadataBehavior" name="Services.CalculatorService">
        <endpoint binding="wsHttpBinding" contract="Contracts.ICalculator"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>

调用的时候报出错误:

Content Type text/xml; charset=utf-8 was not supported by service http://localhost/wcfservices/CalculatorService.svc.  The client and service bindings may be mismatched.

 偶尔一不小心我把配置文件的service节点的name属性改成了Services.CalculatorServices,也就是后面加了"s",服务却能被成功调用了。但是实际上这时候通过浏览器问地址http://localhost/wcfservices/CalculatorService.svc的时候是不成功。

不能理解为何会出现这种情况。做个记号。

转载于:https://www.cnblogs.com/zhstar/archive/2012/02/23/2365877.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值