当前位置:编程学习 > C#/ASP.NET >>

C#调用webservice问题

客户端通过C#编写调用服务器的接口获取数据,服务器端webservice基于xfire,发布在tomcat6上,当服务部署到本地机测试(WinXP)时,测试没问题,当部署到linux时,获取不到数据。
获取的数据格式为网页源代码,数据量比较大,已经调整客户端bindings如下
<bindings>
            <basicHttpBinding>
                <binding name="IMServiceHttpBinding" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>

部署到linux后获取数据是报错如下:
System.ServiceModel.CommunicationException: Error in deserializing body of reply
 message for operation 'getstr'. End element 'out' from namespace 'http://servic
e.com' expected. Found element 'soap:Envelope' from namespace 'http://schemas.xm
lsoap.org/soap/envelope/'. Line 1, position 152021. ---> System.Xml.XmlException
: End element 'out' from namespace 'http://service.com' expected. Found element
'soap:Envelope' from namespace 'http://schemas.xmlsoap.org/soap/envelope/'. Line
 1, position 152021.
   at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader
, String res, String arg1, String arg2, String arg3)
   at System.Xml.XmlExceptionHelper.ThrowEndElementExpected(XmlDictionaryReader
reader, String localName, String ns)
   at System.Xml.XmlBaseReader.ReadEndElement()
   at System.Xml.XmlBaseReader.ReadElementContentAsString()
   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.PartInfo.ReadVa
lue(XmlDictionaryReader reader)
   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializePara
meter(XmlDictionaryReader reader, PartInfo part)
   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeResp
onse(XmlDictionaryReader reader, Object[] parameters)
   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRepl
y(Message message, Object[] parameters)
   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRepl
y(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc&
rpc)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRunt
ime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
   at BigStrtest.ServiceReference1.IMServicePortType.getstr()
   at BigStrtest.ServiceReference1.MServicePortTypeClient.getstr() in E:\VsProje
cts\BigStrtest\BigStrtest\Service References\ServiceReference1\Reference.cs:line
 1354
   at BigStrtest.Program.Main(String[] args) in E:\VsProjects\BigStrtest\BigStrt

各位帮忙看下是怎么回事 c# webservice linux --------------------编程问答-------------------- 命名空间错误,对于跨平台调用,建议你使用webHttpBinding,然后修改格式为Json,那样可以避免很多错误的可能,而且Json的数据量比xml小得多。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,