Welcome

首页 / 软件开发 / WCF / WCF分布式开发常见错误(30)

WCF分布式开发常见错误(30)2011-06-18 博客园 frank_xlWCF分布式开发常见错误(30):Start element "Binary" expected(期望的初始元素是"Binary" )

WCF分布式开发常见错误(30):Start element "Binary" expected(期望的初始元素是"Binary" ). Found "SayHello".

调试WCF4.0代码遇到的错误,目前网络上参考的资料很少,我把这个异常的信息给收集起来,包括解决办法,整理为一篇文章,供大家参考。这个问题目前没什么参考资料。使用Google也搜索不到相关的英文帮资料。分享出来,应该对大家有点参考价值。

【1】错误描述:

这个问题是在调试今天我在调试WCF自定义绑定实现字节流编码ByteStreamMessageEncoding程序例子代码的时候遇到这个错误。客户端抛出的异常是:Start element "Binary" expected(期望的初始元素是"Binary" ). Found "SayHello".

绑定的定义如下:

//创建自定义绑定
ByteStreamMessageEncodingBindingElement byteStream = new ByteStreamMessageEncodingBindingElement();
//TcpTransportBindingElement transport = new TcpTransportBindingElement();
HttpTransportBindingElement transport = new HttpTransportBindingElement();
transport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
transport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
CustomBinding binding = new CustomBinding(byteStream, transport);

操作的定义如下:

//2.服务类,继承接口。实现服务契约定义的操作public class WCFService : IWCFService{//实现接口定义的方法public void SayHello(byte[] b){Console.WriteLine("Hello! {0},Calling at {1} ...", b,DateTime.Now.ToLongTimeString());//return b;}}
【2】错误截图:

运行程序,客户端调用服务操作,抛出的异常截图如下: