当前位置: 代码迷 >> Web Service >> WCF:远程服务器返回异常: (415) Unsupported Media Type
  详细解决方案

WCF:远程服务器返回异常: (415) Unsupported Media Type

热度:1042   发布时间:2012-03-19 22:03:05.0
WCF:远程服务器返回错误: (415) Unsupported Media Type
用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>

------解决方案--------------------
  相关解决方案