zoukankan      html  css  js  c++  java
  • WCF报错

    1、"没有终结点在侦听可以接受消息的 http://localhost:8084/Service1.svc。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参见 InnerException 以了解详细信息"

    一般是地址写错了,此处的重点在InnerException,发现是连不上"127.0.0.1:8084",所以我的WCF服务端有问题

    正确写法如下(控制台作为宿主):

                //创建宿主的基地址
                Uri baseAddress = new Uri("http://localhost:8084/Service1.svc");         
    
                //创建宿主
                using (ServiceHost host = new ServiceHost(typeof(Service1), baseAddress))
                {                
                    //向宿主中添加终结点
                    //host.AddServiceEndpoint(typeof(IService1), new WSHttpBinding() ,"");
                    System.ServiceModel.Channels.Binding httpbinding = new BasicHttpBinding();
    
                    host.AddServiceEndpoint(typeof(IService1), httpbinding, "");
                    
                    //将HttpGetEnabled属性设置为true
                    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                    smb.HttpGetEnabled = true;               
    
                    //将行为添加到Behaviors中
                    host.Description.Behaviors.Add(smb);
                 
                    //打开宿主
                    host.Open();
                    Console.WriteLine("WCF中的HTTP监听已启动....");
                    Console.ReadLine();                
                    //host.Close();
                }

    2、"服务 http://localhost:8082/Service1.svc 不支持内容类型 text/xml; charset=utf-8。客户端和服务绑定可能不匹配。"

          根据上面那句搜的解决方法都不行,重点还是在InnerException里,说希望类型是'text/xml; charset=utf-8',此时异常的类型是'application/soap+xml; charset=utf-8'

     远程服务器返回错误: (415) Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.。

    //写WSHttpBinding报错
    host.AddServiceEndpoint(typeof(IService1), new WSHttpBinding() ,"");
    
    
    //当前场景正确调用方式
    System.ServiceModel.Channels.Binding basicHttpBinding = new BasicHttpBinding();
    host.AddServiceEndpoint(typeof(IService1), basicHttpBinding , "");

    此工厂上启用了手动寻址,因此发送的所有消息都必须进行预寻址

    需要有   webBehavior

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.serviceModel>
        <bindings>
        
          <webHttpBinding>
            <binding name="ServiceReference" />
          </webHttpBinding>
        </bindings>
    
        <behaviors>
          <endpointBehaviors>
            <behavior name="webBehavior">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        
        <client>
       
          <endpoint address="http://XXX.XXX.XXX.XXX:8085/Service.svc?wsdl"
             binding="webHttpBinding" bindingConfiguration="GYSFC_ServiceReference" behaviorConfiguration="webBehavior"         
             contract="ServiceReference.IService" name="ServiceReference" />            
          
        </client>
      </system.serviceModel>
    </configuration>

    约定“IService”的操作“ResetPWD”指定要序列化多个请求正文参数,但没有任何包装元素。如果没有包装元素,至多可序列化一个正文参数。请删除多余的正文参数,或将 WebGetAttribute/WebInvokeAttribute 的 BodyStyle 属性设置为 Wrapped。

    参考:

    解决"415 Cannot process the message because the content type 'application/x-www-form-urlencoded' was not the expected type 'text/xml; charset=utf-8'"

  • 相关阅读:
    Java中常用的四种线程池
    Java中线程与堆栈的关系
    Java线程池构造参数详解
    Java中三目运算符不为人知的坑
    Java并发编程实战 之 对象的共享
    Java并发编程实战 之 线程安全性
    【图文教程】Eclipse for PHP+XAMPP调试配置
    Spket在Eclipse下的安装和配置(图文教程)
    JavaScript编码规范
    FizzBuzzWhizz游戏的高效解法
  • 原文地址:https://www.cnblogs.com/code1992/p/10677397.html
Copyright © 2011-2022 走看看