huh can`t send compressed string ??????? with webservice

M

M. Posseth

Hi ,

I have the following problem

i made an app that sends a xml formatted string across a network through a
webservice ( no i can`t use remoting as i need platform indepandancy )

So to reduce banwidth i implemented Adaptive Huffman this is working
great with the strings in test application`s

### compression method ###
Friend Function strCompress(ByVal strToCompress As String) As String

Dim Bytes() As Byte =
AdaptiveHuffmanProvider.Compress(Encoding.Unicode.GetBytes(strToCompress))

Return Encoding.Unicode.GetString(Bytes)

End Function

######################

this string is normally contained in strXml wich i pass over the webservice

<?xml version="1.0" encoding="utf-16"?>
<tirep>
<errcode>0</errcode>
<Session-ID>{726418b7-b317-47ec-8d3e-473dd07479c0}</Session-ID>
</tirep>


if this string is beeing compressed to 6d#2ti{zB ]?`?c<I: 
i get an error on the client side

System.Web.Services.Protocols.SoapException: Server was unable to process
request. --> There was an error generating the XML document. --> The
surrogate pair is invalid.
at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClient
Message message, WebResponse response, Stream responseStream, Boolean
asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
at NHSDataWebserviceTest.wsNHSBLW.NHSData.GetData(String& strXML) in
C:\Documents and
Settings\Administrator\Desktop\NHSDataWebserviceTestClient\NHSDataWebservice
Test\NHSData.vb:line 25
at NHSDataWebserviceTest.Form1.fobjXMLSendXMLRequest(String strXml,
Boolean& blnSucces) in C:\Documents and
Settings\Administrator\Desktop\NHSDataWebserviceTestClient\NHSDataWebservice
Test\FrmMain.vb:line 370


here is my WSDL


<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://www.nohausystems.com/NHSService/NHSData"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="http://www.nohausystems.com/NHSService/NHSData"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified"
targetNamespace="http://www.nohausystems.com/NHSService/NHSData">
- <s:element name="GetData">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="strXML" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="GetDataResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="GetDataResult"
type="s:boolean" />
<s:element minOccurs="0" maxOccurs="1" name="strXML" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
- <wsdl:message name="GetDataSoapIn">
<wsdl:part name="parameters" element="tns:GetData" />
</wsdl:message>
- <wsdl:message name="GetDataSoapOut">
<wsdl:part name="parameters" element="tns:GetDataResponse" />
</wsdl:message>
- <wsdl:portType name="NHSDataSoap">
- <wsdl:eek:peration name="GetData">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">platform
independent interface wrapper , by specs of the TIREP Schnitstelle Dialog -
Business logic document of the New TIREP development team : Last mod to this
service binary 16-03-2005 , Made by : Michel Posseth [MCP] , info :
(e-mail address removed)</documentation>
<wsdl:input message="tns:GetDataSoapIn" />
<wsdl:eek:utput message="tns:GetDataSoapOut" />
</wsdl:eek:peration>
</wsdl:portType>
- <wsdl:binding name="NHSDataSoap" type="tns:NHSDataSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
- <wsdl:eek:peration name="GetData">
<soap:eek:peration
soapAction="http://www.nohausystems.com/NHSService/NHSData/GetData"
style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:eek:utput>
<soap:body use="literal" />
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>
- <wsdl:service name="NHSData">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/" />
- <wsdl:port name="NHSDataSoap" binding="tns:NHSDataSoap">
<soap:address location="http://127.0.0.1:8080/nhsdata.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>


if strXML contains

<?xml version="1.0" encoding="utf-16"?>
<tirep>
<errcode>0</errcode>
<Session-ID>{726418b7-b317-47ec-8d3e-473dd07479c0}</Session-ID>
</tirep>

then everything works fine

if strXML contains

6d#2ti{zB ]?`?c<I: 

i receive the error

what do i miss ?????
 
M

M. Posseth

Solved it

The trick is that you need to encodebase64 the string before passing it over
the webservice

this explodes the string some more but + - 20% smaller is still good enough
for me

another option would have been to subclass at the sender and receiver side ,
but then i lose my biggest advance , platform indepandancy

as some of my clients are using a Delphi component this is not accepatble
for me

for those of you interested in the technique


Dim bla As String = ">M95835 Brassica napus (clone BnCh25) endochitinase
gene, complete cds" & _

"TCATGAACGGCGCTCATATCATAATTACTTTTAAACATTCATAATTAAAACTTACGTACGCTATATATCC" & _

"TTGACTATTCTTGCAACAACTTTACGAAAGGGGAAAATATAAACACACAAATCTACCAGTACTGTTTATT" & _

"GCACATATTCATTTTTTTTTGCTAAGTATTTATTGCACATATTCATACTCCACGGTCATATATCTAACTA" & _

"GGGAAAATATAAATTTGATGTGATTTAATTTAATTTAACATTCATTGATTGATGTCTCCTGCATGTTGTA" & _

"CTATAAATACCTCTACTTGCCTAAAGATACCATAAAACTCAAAGCAAAAATGAAGTCTTGTCTACTTCTC" & _

"TTTCTCATCTTCTCATTTCTTTTATCATTTTCCTTAGCCGAGCAATGTGGTCGACAAGCGGGAGGAGCTC" & _

"TCTGCCCCAACGGTCTATGCTGCAGCGAGTTCGGATGGTGCGGTGACACCGAAGCTTACTGTAAGCAGCC" & _

"TGGCTGCCAAAGCCAGTGCGGTGGTACTCCTCCTGGCCCCACCGGTGATCTTTCAGGCATCATTTCAAGA" & _

"TCTCAGTTCGACGACATGCTTAAACATAGAAATGATAATGCTTGTCCCGCTAGAGGTTTCTACACTTATG" & _

"ATGCCTTTATCAATGCCGCTAAGTCTTTCCCTGGCTTCGGCACCACCGGAGACACTGCCACAAGGAAGAA" & _

"AGAAATCGCTGCCTTCTTTGGTCAGACTTCCCACGAGACCACCGGTAATAATTGATTATTTTCGTTTTTA" & _

"ACATAATTATTATTGTTTTATTTAGATGAAAAACAAAATCAAAATAACAATTAAAAATATAACAAAATAA" & _

"TTATAAAACAATGTAATTTTTACTTTTATAATTACCATTTTTTTTGCTTAAAATTTTACGAATATAAGAA" & _

"TTTTCCAAAATGACTTAATATAGAAATCTATCAAAATTGTACTTCCTCTGTTTCATAATAAGTGTCATTC" & _

"TAGATTTTTTTTTTCTTGTTATAAAAAAAGTGTCACTTTACAATTCCAAAACAAATTATACTTATTTTCA" & _

"TCTTAAAATTAATTGCAAATTGTATTGGTTTTATAAATAATTTTATTTATCTCAAATACTATTTATCTGG" & _

"AAAATGTAATTAATAACAACTTATATATATTTGCACTACTTTTGTGAAAAGTGTCAAAATGAAACTTATT" & _

"CAGAAACGGAGGGAATATAATACAAAACGTAACACATAAGTTTTCAACGTACATTTTCCCAAATTAAAAT" & _

"TAAACACGTAATGAATACAAAATAAGAAGTGTAATAAATTTAACGTAATTAATAGATTAGACTTTTTTAT" & _

"AATTAACAAAAGTCTAATCTGTTACGCTATTAGACTTGTGACTTAATAAACTAATGAAATGGACGATTGC" & _

"ATGTTGAAGGTGGGTGGGCCACAGCACCAGACGGACCATATTCATGGGGATACTGTTTCAAACAAGAGCA" & _

"GAACCCTTCTTCAAACTACTGTTCACCGAGTGCCGAATGGCCATGCGCATCTGGTAAAAGCTACTACGGA" & _

"AGAGGACCAATGCAGCTATCATGGAACTACAACTACGGACAGTGTGGAAGAGCCATCGGATCTGACTTAC" & _

"TCAACAACCCTGACCTTGTCTCCAACGATCCAGTGATCGCTTTCAAAGCCGCGATTTGGTTTTGGATGAC" & _

"ACCTCAGTCTCCAAAACCGTCGTGCCACGCCGTGATCGTCGGCCAGTGGCAGCCTTCGGATGCTGACCGT" & _

"GCCGCTGGGAGAGTACCGGGTTACGGTGTGATTACGAATATTATTAACGGTGGTTTAGAGTGTGGACGCG" & _

"GCCAAGACGCTAGAGTCGCGGATAGAATTGGATTTTACCAGAGGTACTGTAACATTCTTGGAGTTAATCC" & _

"TGGAGGTAACCTTGATTGTTACAACCAAAGGTCCTTTGCTTCTGTTAACTTCTTCCTTGACGCTGCTATT" & _

"TAATAAGGAGTGTTATGCAGCTTTGTATCCAAAAGCAATAAGGGATTAATATCAAACTAAATAAAACTCT" & _

"TTGTCGTATCTTATTCTTAGCTCCACTCCTCATTTTTTGAAGCATGTACCAAATAACCTAAAGCTAATCT" & _

"TTCTCTAATGAGATAAACCAAACTAACAAATCTTGTTTTGATCGTTCAACTAACTTAAAACTGAACTTTC" & _

"TAATTACATTTTCGGATTTTGTTTATGAGAGTTGGAATGGACAAAGCAAGATATAATTCTATTACATTTA" & _

"CAAGTTTCAAAACAGTTCAAGCGAGTTTCGCATAACATGTCGCTATCTCCAAGCATCATTTCAAGTGTAA" & _

"GCCTCGTAGTATAAAAATTTTGGCTACAATAACCGGTTTAGACCGAAGTAAACCAATCTAAAACTCCAAT" & _

"AGCCTCTATTTCTTAAACGTTACAAGACGAAAGTCAATTGACATTGAACCAAGTGTGAACACTATTAAAG" & _

"AGAAAGCACTCTATTAAACCAAATGTTAGATGTAAACCAAAATTAAAACTAAACCGAAAGTAAACCAAAA" & _

"ACTTATTGGGCACATTTACTGCGGGGACACAGAGTCCAACGACCTGTAACCGCAGATGATTAATATCCGA" & _

"AAATATCTAAAAAGATCAGAGCACCGAACCAAAATATAAAGTGAAGATGATGAAAAGCTGTTTCTCAATC" & _

"TTCTTCTCCATCTTCGTCTCCTCTAGTGATTTAGGGTTCTGCAACGACGAAGACATGGCTTTACTCGGCG" & _

"GCGTTCGCGATGTACCTGCTAATCAGAACAGCGGCGAGGTCGAGAGCCTCGCTCGTTTCGCCGTCGATGA" & _

"GCATAACAAGAAAGAGGTTCATCTCTCTCTCTCTCTCTCTCGATTAGTGATCCAAATCGCGATTAGAGTA" & _

"AATTGTCATAGTCTCGCTTAGTATGTGATCTGATCATTGAGTGACGATTGTAGAATTCGCTGCTGGAGTT" & _

"TGCGAGGGTGGTGAGGCGAGACAGTTGTGCGGACGATGCATGACTGACGCTGAGATCGACTGCAGGCATG" & _

"CAA"

Dim Bytes() As Byte =
AdaptiveHuffmanProvider.Compress(Encoding.UTF8.GetBytes(bla))

Dim test As String = System.Convert.ToBase64String(Bytes, 0, _

Bytes.Length)

MsgBox(Len(test))

MsgBox(test)' send this string over the wire ( through the webservice )

###############################

'receiver side

'make it a byt array again

Dim bytes2() As Byte = System.Convert.FromBase64String(test)

bytes2 = AdaptiveHuffmanProvider.Decompress(bytes2)

Dim decoded As String = Encoding.UTF8.GetString(bytes2)

MsgBox(Len(decoded))

' well here is the original string back

' P.S. this technique is verry fast :)



M. Posseth said:
Hi ,

I have the following problem

i made an app that sends a xml formatted string across a network through a
webservice ( no i can`t use remoting as i need platform indepandancy )

So to reduce banwidth i implemented Adaptive Huffman this is working
great with the strings in test application`s

### compression method ###
Friend Function strCompress(ByVal strToCompress As String) As String

Dim Bytes() As Byte =
AdaptiveHuffmanProvider.Compress(Encoding.Unicode.GetBytes(strToCompress))

Return Encoding.Unicode.GetString(Bytes)

End Function

######################

this string is normally contained in strXml wich i pass over the webservice

<?xml version="1.0" encoding="utf-16"?>
<tirep>
<errcode>0</errcode>
<Session-ID>{726418b7-b317-47ec-8d3e-473dd07479c0}</Session-ID>
</tirep>


if this string is beeing compressed to 6d#2ti{zB ]?`?c<I: 
i get an error on the client side

System.Web.Services.Protocols.SoapException: Server was unable to process
request. --> There was an error generating the XML document. --> The
surrogate pair is invalid.
at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClient
Message message, WebResponse response, Stream responseStream, Boolean
asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
at NHSDataWebserviceTest.wsNHSBLW.NHSData.GetData(String& strXML) in
C:\Documents and
Settings\Administrator\Desktop\NHSDataWebserviceTestClient\NHSDataWebservice
Test\NHSData.vb:line 25
at NHSDataWebserviceTest.Form1.fobjXMLSendXMLRequest(String strXml,
Boolean& blnSucces) in C:\Documents and
Settings\Administrator\Desktop\NHSDataWebserviceTestClient\NHSDataWebservice
Test\FrmMain.vb:line 370


here is my WSDL


<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://www.nohausystems.com/NHSService/NHSData"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="http://www.nohausystems.com/NHSService/NHSData"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified"
targetNamespace="http://www.nohausystems.com/NHSService/NHSData">
- <s:element name="GetData">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="strXML" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="GetDataResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="GetDataResult"
type="s:boolean" />
<s:element minOccurs="0" maxOccurs="1" name="strXML" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
- <wsdl:message name="GetDataSoapIn">
<wsdl:part name="parameters" element="tns:GetData" />
</wsdl:message>
- <wsdl:message name="GetDataSoapOut">
<wsdl:part name="parameters" element="tns:GetDataResponse" />
</wsdl:message>
- <wsdl:portType name="NHSDataSoap">
- <wsdl:eek:peration name="GetData">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">platform
independent interface wrapper , by specs of the TIREP Schnitstelle Dialog -
Business logic document of the New TIREP development team : Last mod to this
service binary 16-03-2005 , Made by : Michel Posseth [MCP] , info :
(e-mail address removed)</documentation>
<wsdl:input message="tns:GetDataSoapIn" />
<wsdl:eek:utput message="tns:GetDataSoapOut" />
</wsdl:eek:peration>
</wsdl:portType>
- <wsdl:binding name="NHSDataSoap" type="tns:NHSDataSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
- <wsdl:eek:peration name="GetData">
<soap:eek:peration
soapAction="http://www.nohausystems.com/NHSService/NHSData/GetData"
style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:eek:utput>
<soap:body use="literal" />
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>
- <wsdl:service name="NHSData">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/" />
- <wsdl:port name="NHSDataSoap" binding="tns:NHSDataSoap">
<soap:address location="http://127.0.0.1:8080/nhsdata.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>


if strXML contains

<?xml version="1.0" encoding="utf-16"?>
<tirep>
<errcode>0</errcode>
<Session-ID>{726418b7-b317-47ec-8d3e-473dd07479c0}</Session-ID>
</tirep>

then everything works fine

if strXML contains

6d#2ti{zB ]?`?c<I: 

i receive the error

what do i miss ?????
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top