zoukankan      html  css  js  c++  java
  • 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的时候是不成功。

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

  • 相关阅读:
    第5章 继承
    第4章 对象和类
    第3章 java的基本程序设计结构
    Java读写properties格式配置文件
    Net学习日记_三层_2
    Net学习日记_三层_1_登录页面总结篇_残缺版
    Net学习日记_三层_1
    Net学习日记_SQL进阶_2
    Net学习日记_SQL进阶_1
    Net学习日记_ADO.Net_3_案例
  • 原文地址:https://www.cnblogs.com/zhstar/p/2365877.html
Copyright © 2011-2022 走看看