我有一个silverlight应用程序,它与ASP.NET网站中的WCF服务对话。下面的代码工作:Silverlight WCF使用BasicHttpBinding,使用CustomBinding/BinaryMessageEncoding时出现“HTTP 415 Unsupported Media Type”异常
var service = new ChannelFactory<IService>(new BasicHttpBinding()
{
MaxReceivedMessageSize = int.MaxValue
},
new EndpointAddress(Settings.ServiceUrl)).CreateChannel();
但我真的想利用“二进制编码”。要使用二进制编码运行服务,您不能使用BasicHttpBinding,您需要使用CustomBinding!以下代码在相同位置使用,但会从Web服务器中产生HTTP 415 Unsupported媒体类型状态。在调试会话中,服务器上没有达到断点。
var service = new ChannelFactory<IService>(new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement()
{
MaxReceivedMessageSize = int.MaxValue
}),
new EndpointAddress(Settings.ServiceUrl)).CreateChannel();
我需要帮助找出为什么这个设置不起作用! BTW这里是我的web配置服务节在服务器端:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="myBinding">
<binaryMessageEncoding />
<httpTransport authenticationScheme="Negotiate"/>
</binding>
</customBinding>
</bindings>
<services>
<service name="myService">
<endpoint address="" binding="customBinding" bindingConfiguration="myBinding" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wcfServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
是的,谢谢你指出,我已经编辑了上面的代码。我再次使用web.config中的 元素重试了它,并且问题完全没有改变,BasicHttpBinding有效,CustomBinding引发NotFound异常。 –
nachonachoman
2010-09-07 01:26:24
更新 - 感谢您的帮助。我能够调整本地URL并添加一个点“。”到地址,这使得提琴手能够监控本地流量。现在我可以看到真正的罪魁祸首是来自调试Web服务器的HTTP 415 Unsupported Media Type。 – nachonachoman 2010-10-10 23:51:57
调试Web服务器?你的意思是卡西尼(包含在Visual Studio中的网络服务器)?我认为卡西尼不支持二进制编码。在开发高级WCF服务时,您应该使用IIS或自托管。 – 2010-10-11 07:16:55