0

i am new and need some help. i have created an wcf service application in visual studio and write an simple method of login which receive an parameter userid & password then return an object of logged user object which have two fields name and organization.

LoggedUser Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;

namespace crmpp_android_service
{
    public class LoggedUser
    {
        public string name;
        public string organization;
        [DataMember]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        [DataMember]
        public string Organization
        {
            get { return organization; }
            set { organization = value; }
        }
    }
}

OperationContract:

[OperationContract]
        [WebInvoke(Method = "GET",
           ResponseFormat = WebMessageFormat.Json,
             RequestFormat = WebMessageFormat.Json,
            UriTemplate = "login/?userid={userid} & pass={pass}"
        )]
        [Description("User Login return username & Organization currently affiliated")]
        LoggedUser login(string userid, string pass);

Method Implementation in Service1.svc:

  public LoggedUser login(string userid , string pass)
        {
            LoggedUser log_usr = new LoggedUser();
            log_usr.name = "Ahsan Mehdi";
            log_usr.organization = "JDC";
            return log_usr;
        }

but when i run application by pressing ctrl+F5 it open an wcf test Client like this and return data. enter image description here

I am unable to get response from android app or simply from browser when i write URL for service it shows me page like that.

http://localhost:57127/Service1.svc

enter image description here

and when complete url like this

http://localhost:57127/Service1.svc/login/?userid=abc123&pass123

it returns nothing any guidelike or help please as soon as possible.

syed Ahsan Jaffri
  • 1,160
  • 2
  • 14
  • 34

2 Answers2

1

As per my understand you want to access this WCF url which is hosted on your localhost machine not on IIS. For accessing your localhost webservice use this instead of localhost

http://10.0.2.2:Port/Service1.svc/login/?userid=abc123&pass123

And on IIS use the system IP which is assigned to you.

http://192.168.0.123:Port/Service1.svc/login/?userid=abc123&pass123

I hope this will clear your issue regarding connecting to android project.

Pro_Zeck
  • 405
  • 2
  • 13
  • 25
0

Get WCFstorm. When you run it, add a new service, and copy the url of the service (in your screenshot, it's showing as:

localhost:57127/Service.svc

That will allow you to test the service.

This is what I use at work for testing WCF services.

Another tool I use is Fiddler.

Bardicer
  • 1,405
  • 4
  • 26
  • 43
  • thanks for reply but actually i want to access these methods of services from android application. where i will have to use service method path as **http://localhost:57127/Service1.svc/login/?userid=abc123&pass123** so this should return some data in json formate but it is not. – syed Ahsan Jaffri Oct 17 '13 at 03:18
  • What endpoints do you have set up? Are you able to get a wsdl? – Bardicer Oct 17 '13 at 03:27
  • i am getting an xml page from this url **http://localhost:57127/Service1.svc?singleWsdl** and this url **svcutil.exe http://localhost:57127/Service1.svc?wsdl** does not work – syed Ahsan Jaffri Oct 17 '13 at 03:34
  • In your screenshot, the url of the wsdl you're looking for should be localhost:57127/Service1.svc?wsdl, or did you move it? Also, I don't know of any way to invoke a service through a browser url. You will need to set up endpoints and call those. http://stackoverflow.com/questions/802518/invoking-wcf-service-method-through-a-browser may help explain it a little better. – Bardicer Oct 17 '13 at 03:37
  • Thanks for your replies. i have not moved that service and i am able to test this service through wcf test client correctly. let me check endpoints – syed Ahsan Jaffri Oct 17 '13 at 03:53