Not getting response from .net Services

102 views
Skip to first unread message

niti...@gmail.com

unread,
Apr 4, 2013, 4:31:58 AM4/4/13
to codenameone...@googlegroups.com


i am using Webservice.java  file got from this forum but i dont know how to use this 


i try
 WebServices req=new WebServices() {
@Override
public void loadData() {
// TODO Auto-generated method stub
}
@Override
public String getInputParams() {
// TODO Auto-generated method stub
return null;
}
};
        req.setPost(false);
        req.setHttpMethod("POST");
        NetworkManager.getInstance().addToQueue(req);


but getting null response



i have to parse this response 

<string xmlns="http://tempuri.org/">
{ 'Root': { 'data': [{'EmpId': '1','EmpName': 'Suri','Department': 'IT Apps','Designation': 'Developer','Process': 'IT Application','DOB': '10/7/1979 12:00:00 AM','Address': '415','PhoneNo': '9818423532','LandlineNo': '22222222','ExtnNo': '356','Gender': 'M'}] }}
</string>

below is the .net method which  i call ..


POST /BasicFunctions.asmx HTTP/1.1
Host: 203.122.51.66
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/FetchAllEmpDetails"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <FetchAllEmpDetails xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>
WebServices.java

unk...@gmail.com

unread,
Apr 4, 2013, 7:38:55 AM4/4/13
to codenameone...@googlegroups.com, niti...@gmail.com
i managed to communicate with a .net service by doing the following, maybe it helps:

.NET PART:
- new wcf service
- CalculationService.svc:
public int GetSum(string a, string b)
{
   
return Convert.ToInt32(a) + Convert.ToInt32(b);
}

- ICalculationService.cs:
[ServiceContract]
public interface ICalculationService
{
   
[OperationContract]    
   
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetSum?a={a}&b={b}")]
   
int GetSum(string a, string b);  
}

-web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>

 
<system.web>
   
<compilation debug="true" targetFramework="4.0" />
 
</system.web>
 
<system.serviceModel>
   
   
   
   
<services>
     
<service name="CalculationService.CalculationService" behaviorConfiguration="ServiceBehaviour">
       
       
<endpoint address="" binding="webHttpBinding" contract="CalculationService.ICalculationService" behaviorConfiguration="web" />

     
</service>
   
</services>
   
   
<behaviors>
     
<serviceBehaviors>
       
<behavior name="ServiceBehaviour">
         
<serviceMetadata httpGetEnabled="true"/>
         
<serviceDebug includeExceptionDetailInFaults="false"/>
       
</behavior>
     
</serviceBehaviors>
     
<endpointBehaviors>
       
<behavior name="web">
         
<webHttp/>
       
</behavior>
     
</endpointBehaviors>
   
</behaviors>
   
   
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
 
</system.serviceModel>
 
 
<system.webServer>
   
<modules runAllManagedModulesForAllRequests="true"/>
 
</system.webServer>
 
</configuration>



Codename One Part:

- 3 textfields (txtValue1, txtValue2, txtResult)
- 1 button (btnCalculate)

protected void onMain_BtnCalculateAction(final Component c, ActionEvent event)
   
{        
       
super.onMain_BtnCalculateAction(c, event);
       
       
ConnectionRequest r = new ConnectionRequest()
       
{
           
Hashtable h;
           
@Override
           
protected void postResponse()
           
{              
                findTxtResult
(c).setText(h.get("GetSumResult").toString());
           
}
           
           
@Override
           
protected void readResponse(InputStream input) throws IOException
           
{
               
JSONParser p = new JSONParser();
                h
= p.parse(new InputStreamReader(input));
               
String result = h.get("GetSumResult").toString();
               
           
}
           
       
};
       
        r
.setUrl("http://localhost:52581/CalculationService.svc/GetSum");
        r
.setPost(false);
       
       
String value1 = findTxtValue1().getText();
       
String value2 = findTxtValue2().getText();
               
        r
.addArgument("a", value1);
        r
.addArgument("b", value2);
       
       
InfiniteProgress progress = new InfiniteProgress();
       
Dialog dlg = progress.showInifiniteBlocking();
       
        r
.setDisposeOnCompletion(dlg);
       
NetworkManager.getInstance().addToQueue(r);
   
}


Shai Almog

unread,
Apr 4, 2013, 1:46:56 PM4/4/13
to codenameone...@googlegroups.com, niti...@gmail.com
That's not one of our classes so I can't help you there. You can however use the network monitor tool in the simulator and see exactly what is sent/received by the application.

scot...@gmail.com

unread,
Dec 27, 2013, 5:12:49 PM12/27/13
to codenameone...@googlegroups.com, niti...@gmail.com
Did you ever get this working?
Reply all
Reply to author
Forward
0 new messages