WCF:远程服务器返回错误: (415) Unsupported Media Type

luyanvv 2012-02-17 11:16:30
用ServiceProxyFactory(客户端顶点名称)来获取WCF服务里的信息

错误信息:

WebException: 远程服务器返回错误: (415) Unsupported Media Type。]

System.Net.HttpWebRequest.GetResponse() +6038659

System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +48

[ProtocolException: 服务 http://localhost:1330/host/Service.svc 不支持内容类型 application/soap+xml; charset=utf-8。客户端和服务绑定可能不匹配。]

System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9464463
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
testlib.Itestclass.sayHello() +0
_Default.Page_Load(Object sender, EventArgs e) in e:\Code\TestWCF\client\Default.aspx.cs:15
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

-----------配置-------------------------------

Host:

<system.serviceModel>
<services>
<service name="testlib.testclass">
<endpoint binding="ws2007HttpBinding" contract="testlib.Itestclass" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1330/host/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="1000" maxConcurrentInstances="50000" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<ws2007HttpBinding>
<binding>
<security mode="None"></security>
</binding>
</ws2007HttpBinding>
</bindings>
</system.serviceModel>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Client:

<system.serviceModel>
<client>
<endpoint address="http://localhost:1330/host/Service.svc" binding="ws2007HttpBinding" contract="testlib.Itestclass" name="test"/>
</client>
<bindings>
<ws2007HttpBinding>
<binding name="NoneSecurity" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
<readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000" maxBytesPerRead="120000"/>
<security mode="None"/>
</binding>
</ws2007HttpBinding>
</bindings>
</system.serviceModel>
</configuration>
...全文
1234 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
luyanvv 2012-02-20
  • 打赏
  • 举报
回复
粗心大意的错~~~~~~~

.svc文件的Service忘了改了~
机器人 2012-02-17
  • 打赏
  • 举报
回复
你是用 IIS Host 么?

ws2007HttpBinding 改为 wsHttpBinding 试试。
luyanvv 2012-02-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cmic 的回复:]
感觉是你binding 不应该加名字,把名字去了看看。
<ws2007HttpBinding>
<binding name="NoneSecurity" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
<readerQuotas maxStringConten……
[/Quote]
一样的错误呢~~~~~
luyanvv 2012-02-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fangxinggood 的回复:]
你是用 IIS Host 么?

ws2007HttpBinding 改为 wsHttpBinding 试试。
[/Quote]
改了,也还是一样的错误
CMIC 2012-02-17
  • 打赏
  • 举报
回复
感觉是你binding 不应该加名字,把名字去了看看。
<ws2007HttpBinding>
<binding name="NoneSecurity" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
<readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000" maxBytesPerRead="120000"/>
<security mode="None"/>
</binding>
</ws2007HttpBinding>

如果不在endpoint 制定bindingConfiguration 属性,默认它会使用没名字的<binding>但你指定了名字,所以它用的不是这个bing了。

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧