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。
参考:
最新文章
- SSRS 2008 R2 错误:Timeout expired. The timeout period
- mysql:忘记root密码
- Yocto开发笔记之《Makefile编写》(QQ交流群:519230208)
- 介绍linux下利用编译bash设置root账号共用的权限审计设置
- mount: unknown filesystem type &#39;LVM2_member&#39;解决方案
- iOS开发--SWRevealViewController
- [html5] (Notification) 桌面通知
- Java邮件开发(JavaMail)
- SQL*Net message from client
- Entrez检索实例 - NCBI
- coreldraw圆形裁剪
- oracle表空间增长异常或表空间占用过高问题分析
- Python爬虫之selenium各种注意报错
- 设置chrome浏览器背景颜色
- Spring-MVC运行原理
- [转帖]再次提醒Google Chrome用户应尽快升级浏览器到72.0.3626.121
- MT【297】任意四边形的一个向量性质
- rhadoop linear regression 问题
- NSKeyValueObserving.m
- java下载文件注意点