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 , "");

 

 

 

参考:

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

 

转载于:https://www.cnblogs.com/code1992/p/10677397.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值