Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I need to consume a webservice(developed in Java) in C#.net.

In this I need to pass the parameter name as db:hostname in request from c#.net to Java.

XML
<soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:dev="XXXX/devicemanagement/device" xmlns:com="XXXX/ws/common" xmlns:com1="XXXX/types/common">
   <soap:header />
   <soap:body>
      <dev:adddevicesrequest xmlns:db="XXXX/deviceattribute/basicinfo" xmlns:dauth="XXXX/deviceattribute/authentication" xmlns:dgauth="XXXXX/devicegroupattribute/authentication">
        <dev:device>
              <dev:attribute>
                    <com:name>db:HostName</com:name>
                    <com:stringvalue>192.168.200.101</com:stringvalue>
              </dev:attribute>
              <dev:attribute>
                    <com:name>db:DisplayDeviceName</com:name>
                    <com:stringvalue>d01</com:stringvalue>
              </dev:attribute>
              <dev:attribute>
                      <com:name>db:ModelCode</com:name>
                      <com:stringvalue>ModelCode01</com:stringvalue>
               </dev:attribute>
               <dev:attribute>
                      <com:name>db:SerialNumber</com:name>
                      <com:stringvalue>12301</com:stringvalue>
               </dev:attribute>
        </dev:device>
      </dev:adddevicesrequest>
   </soap:body>
</soap:envelope>




<big>When I pass parameter as "db:hostname" from c# to java, it is getting encrypted at java end as "db_x003A_hostname" which means colon (":") is getting converted to " _x003A" at java service. This results an error as "invalid parameter name".</big>

Please help me in resolving this error.

Thanks in advance for your help.
Posted
Updated 21-Apr-14 18:48pm
v3
Comments
Prasad Khandekar 21-Apr-14 9:57am    
Do you mind sharing a code snippet for the C# Client?
balu12345 21-Apr-14 14:08pm    
Thanks for coming forward to help me..

Just need to pass parameter name as "db:hostname" and value as "abcd" from c# client to Java webservice.
It very normal plain basic coding of consuming java webservice.. but strucked with ":" changed as "_x003A_"...

You need to use UTF8 Encoding.
All others will fail.
 
Share this answer
 
Comments
balu12345 21-Apr-14 14:21pm    
Hi Mr.TorstenH,

Thanks for your help
Please guide me how to pass this UTF8 encoded parameter from c# client to Java webservice.
I don't have any control on Java web service.

Request you to share me skeleton/pseudo code
TorstenH. 22-Apr-14 1:59am    
try this:

byte[] bytes = Encoding.Default.GetBytes(myString);
myString = Encoding.UTF8.GetString(bytes);

That should bring your String into UTF-8 encoding (I'm not into C#, so you might need to check if that's correct).
Please also check if the String is put in correctly in the soap-request and - if possible - if it is extracted correct on the other side.
Shubhashish_Mandal 22-Apr-14 0:32am    
+it should be in request header
Colon is not a valid character inside a element name. Colon is used to pair the namespace and the element name. Here if you want the Db to go along then you might need to add it as a namespace.

C#
// Serialize the hostname field as an attribute with the given namspace
[XmlAttribute( Namespace ="www.db.com")]
public string hostname;


http://www.diranieh.com/NETSerialization/XMLSerialization.htm#Working%20with%20XML%20Namespaces[^]
 
Share this answer
 
Comments
balu12345 22-Apr-14 0:36am    
Hi Guruprasad,

Thanks for your help

<soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:dev="XXXX/devicemanagement/device" xmlns:com="XXXX/ws/common" xmlns:com1="XXXX/types/common">
<soap:header>
<soap:body>
<dev:adddevicesrequest xmlns:db="XXXX/deviceattribute/basicinfo"
="" xmlns:dauth="XXXX/deviceattribute/authentication" xmlns:dgauth="XXXXX/devicegroupattribute/authentication">
<dev:device>
<dev:attribute>
<com:name>db:HostName
<com:stringvalue>192.168.200.101

<dev:attribute>
<com:name>db:DisplayDeviceName
<com:stringvalue>d01

<dev:attribute>
<com:name>db:ModelCode
<com:stringvalue>ModelCode01

<dev:attribute>
<com:name>db:SerialNumber
<com:stringvalue>12301






I tried your solution but it didn't resolved my issue,
To be more clear,if you see above request "I need to pass parameter values like "db:hostname","db:DisplayDeviceName".... and so on.. from C# client to Java websercice"

Please help me at earliest possible..
Guruprasad.K.Basavaraju 22-Apr-14 12:35pm    
Hi Balu,

Can you show me the code where you are creating this XML ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900