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的时候是不成功。

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

  • 相关阅读:
    django 使用form组件提交数据之form表单提交
    django from验证组件
    django中间件
    gin中http重复解析body数据失败
    go 常用工具链
    git 提交规范
    go简单实现heap
    Go优雅实现选传参数
    [已解决]protoc-gen-go: unable to determine Go import path for "xxx.proto"
    Go编译工具命令
  • 原文地址:https://www.cnblogs.com/zhstar/p/2365877.html
Copyright © 2011-2022 走看看