WCF学习笔记二
客户端调用WCF服务出现以下错误:
“/”应用程序中的服务器错误。
远程服务器返回错误: (415) Unsupported Media Type。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Net.WebException: 远程服务器返回错误: (415) Unsupported Media Type。
堆栈跟踪:
[WebException: 远程服务器返回错误: (415) Unsupported Media Type。] |
观察堆栈可以知道,这是因为客户端和服务端绑定不匹配造成的,代码如下:
服务端配置节点信息:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<!-- Before deployment, you should remove the returnFaults behavior configuration to avoid disclosing information in exception messages -->
<service name="SOA.Services.SearchConfigBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.ISearchConfig" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.ISearchConfig" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.SubjectBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.ISubject" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.ISubject" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.AreaBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.IArea" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.IArea" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.YearBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.IYear" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.IYear" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="a1">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
客户端配置节点信息:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_SubjectContract" />
<binding name="BasicHttpBinding_AreaContract" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
<binding name="BasicHttpBinding_SearchConfigContract" />
<binding name="BasicHttpBinding_YearContract" />
</basicHttpBinding>
<wsHttpBinding>
<binding name="MetadataExchangeHttpBinding_SubjectContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_AreaContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_SearchConfigContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_YearContract">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1234/AreaService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_AreaContract" contract="AreaService.AreaContract"
name="BasicHttpBinding_AreaContract" />
<endpoint address="http://localhost:1234/SearchConfigService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SearchConfigContract"
contract="SearchConfigService.SearchConfigContract" name="BasicHttpBinding_SearchConfigContract" />
<endpoint address="http://localhost:1234/SubjectService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SubjectContract"
contract="SubjectService.SubjectContract" name="BasicHttpBinding_SubjectContract" />
<endpoint address="http://localhost:1234/YearService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_YearContract" contract="YearService.YearContract"
name="BasicHttpBinding_YearContract" />
</client>
</system.serviceModel>
所以,只需要将客户端和服务端的配置保持一致即可。
代码如下:
1.使用basicHttpBinding:
客户端配置节点信息: <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_SubjectContract" />
<binding name="BasicHttpBinding_AreaContract" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
<binding name="BasicHttpBinding_SearchConfigContract" />
<binding name="BasicHttpBinding_YearContract" />
</basicHttpBinding>
<wsHttpBinding>
<binding name="MetadataExchangeHttpBinding_SubjectContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_AreaContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_SearchConfigContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_YearContract">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1234/AreaService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_AreaContract" contract="AreaService.AreaContract"
name="BasicHttpBinding_AreaContract" />
<endpoint address="http://localhost:1234/SearchConfigService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SearchConfigContract"
contract="SearchConfigService.SearchConfigContract" name="BasicHttpBinding_SearchConfigContract" />
<endpoint address="http://localhost:1234/SubjectService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SubjectContract"
contract="SubjectService.SubjectContract" name="BasicHttpBinding_SubjectContract" />
<endpoint address="http://localhost:1234/YearService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_YearContract" contract="YearService.YearContract"
name="BasicHttpBinding_YearContract" />
</client>
</system.serviceModel> 服务端配置节点信息: <system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<!-- Before deployment, you should remove the returnFaults behavior configuration to avoid disclosing information in exception messages -->
<service name="SOA.Services.SearchConfigBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.ISearchConfig" binding="basicHttpBinding"/>
<endpoint contract="SOA.Contract.ISearchConfig" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.SubjectBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.ISubject" binding="basicHttpBinding"/>
<endpoint contract="SOA.Contract.ISubject" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.AreaBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.IArea" binding="basicHttpBinding"/>
<endpoint contract="SOA.Contract.IArea" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.YearBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.IYear" binding="basicHttpBinding"/>
<endpoint contract="SOA.Contract.IYear" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="a1">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
使用basicHttpBinding
2.使用wsHttpBinding:
客户端配置节点信息: <system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="BasicHttpBinding_SubjectContract" />
<binding name="BasicHttpBinding_AreaContract" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
<binding name="BasicHttpBinding_SearchConfigContract" />
<binding name="BasicHttpBinding_YearContract" />
</wsHttpBinding>
<basicHttpBinding>
<binding name="MetadataExchangeHttpBinding_SubjectContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_AreaContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_SearchConfigContract">
<security mode="None" />
</binding>
<binding name="MetadataExchangeHttpBinding_YearContract">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1234/AreaService.svc" binding="wsHttpBinding"
bindingConfiguration="BasicHttpBinding_AreaContract" contract="AreaService.AreaContract"
name="BasicHttpBinding_AreaContract" />
<endpoint address="http://localhost:1234/SearchConfigService.svc"
binding="wsHttpBinding" bindingConfiguration="BasicHttpBinding_SearchConfigContract"
contract="SearchConfigService.SearchConfigContract" name="BasicHttpBinding_SearchConfigContract" />
<endpoint address="http://localhost:1234/SubjectService.svc"
binding="wsHttpBinding" bindingConfiguration="BasicHttpBinding_SubjectContract"
contract="SubjectService.SubjectContract" name="BasicHttpBinding_SubjectContract" />
<endpoint address="http://localhost:1234/YearService.svc" binding="wsHttpBinding"
bindingConfiguration="BasicHttpBinding_YearContract" contract="YearService.YearContract"
name="BasicHttpBinding_YearContract" />
</client>
</system.serviceModel> 服务端配置节点信息: <system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<!-- Before deployment, you should remove the returnFaults behavior configuration to avoid disclosing information in exception messages -->
<service name="SOA.Services.SearchConfigBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.ISearchConfig" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.ISearchConfig" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.SubjectBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.ISubject" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.ISubject" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.AreaBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.IArea" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.IArea" binding="mexHttpBinding" address="mex"/>
</service>
<service name="SOA.Services.YearBiz" behaviorConfiguration="a1">
<endpoint contract="SOA.Contract.IYear" binding="wsHttpBinding"/>
<endpoint contract="SOA.Contract.IYear" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="a1">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
使用wsHttpBinding
WCF学习笔记二的更多相关文章
- WCF学习笔记之事务编程
WCF学习笔记之事务编程 一:WCF事务设置 事务提供一种机制将一个活动涉及的所有操作纳入到一个不可分割的执行单元: WCF通过System.ServiceModel.TransactionFlowA ...
- WCF学习笔记之传输安全
WCF学习笔记之传输安全 最近学习[WCF全面解析]下册的知识,针对传输安全的内容做一个简单的记录,这边只是简单的记录一些要点:本文的内容均来自[WCF全面解析]下册: WCF的传输安全主要涉及认证. ...
- WCF 学习笔记之双工实现
WCF 学习笔记之双工实现 其中 Client 和Service为控制台程序 Service.Interface为类库 首先了解契约Interface两个接口 using System.Service ...
- WPF的Binding学习笔记(二)
原文: http://www.cnblogs.com/pasoraku/archive/2012/10/25/2738428.htmlWPF的Binding学习笔记(二) 上次学了点点Binding的 ...
- AJax 学习笔记二(onreadystatechange的作用)
AJax 学习笔记二(onreadystatechange的作用) 当发送一个请求后,客户端无法确定什么时候会完成这个请求,所以需要用事件机制来捕获请求的状态XMLHttpRequest对象提供了on ...
- [Firefly引擎][学习笔记二][已完结]卡牌游戏开发模型的设计
源地址:http://bbs.9miao.com/thread-44603-1-1.html 在此补充一下Socket的验证机制:socket登陆验证.会采用session会话超时的机制做心跳接口验证 ...
- JMX学习笔记(二)-Notification
Notification通知,也可理解为消息,有通知,必然有发送通知的广播,JMX这里采用了一种订阅的方式,类似于观察者模式,注册一个观察者到广播里,当有通知时,广播通过调用观察者,逐一通知. 这里写 ...
- java之jvm学习笔记二(类装载器的体系结构)
java的class只在需要的时候才内转载入内存,并由java虚拟机的执行引擎来执行,而执行引擎从总的来说主要的执行方式分为四种, 第一种,一次性解释代码,也就是当字节码转载到内存后,每次需要都会重新 ...
- WCF 学习笔记之异常处理
WCF 学习笔记之异常处理 1:WCF异常在配置文件 <configuration> <system.serviceModel> <behaviors> <s ...
随机推荐
- linux shell中的EOF
关键词:EOF 在平时的运维工作中,我们经常会碰到这样一个场景:执行脚本的时候,需要往一个文件里自动输入N行内容.如果是少数的几行内容,还可以用echo追加方式,但如果是很多行,那么单纯用echo追加 ...
- JVM Java 内存区域透彻分析(转)
出处: Java 内存区域透彻分析 Java8内存模型—永久代(PermGen)和元空间(Metaspace) 这篇文章主要介绍Java内存区域,也是作为Java虚拟机的一些最基本的知识,理解了这 ...
- MogileFS表说明
MogileFS大致的表说明如下 checksum:用来存放文件的校验和class:文件分类定义device:主机上的可用设备定义,包括设备可用空间,使用的权重等信息domain:域定义信息file: ...
- rman备份跳过read only数据文件,减少备份总量,加快备份时间
客户需求,RMAN备份时间过长,想缩短备份时间,优化备份. 客户基于表空间进行历史数据归档的方式,将历史的表空间进行read only,想让RMAN跳过只读表空间,减少RMAN备份的数据总量,从而缩短 ...
- Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向
Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...
- Asp.net core中间件实现原理及用法解说
简述asp.net core中间件的实现思路 原文地址:https://www.cnblogs.com/shengyu-kmust/p/11583974.html 一次http请求的过程,就是对一个R ...
- Navicat远程连接centos上mysql出错
原因1:mysql账户是不允许远程连接 参考:centos安装mysql(for 小白) 打开远程连接 原因2:3306端口未开启 开启端口:iptables -I INPUT -p tcp --dp ...
- vscode 使用ESLint 自动检查,保存时自动格式化
1:全局安装eslint `npm install -g eslint`2: 打开vscode 点击 “文件”----->“首选项”---->“设置”,在右侧“用户设置/settings. ...
- MySQL之日期时间函数
1.NOW() 用法:显示当前日期和时间 举例: mysql> select NOW(); +---------------------+ | NOW() | +-------------- ...
- 新版mysql的配置文件my.ini位置
在网上的博客上找了好久的my.ini,一直找不到.最后发现原来新版本的mysql已经不把my.ini放在原始的安装目录了.而是放在了C:/ProgramData下.