Access Web Service via Local Area Network - c#

My problem is that I tried changing the localhost to ip address/computer name and still cannot access. My web service link goes like this http://localhost:1228/TryService.asmx?op=HelloWorld.
How can I make it accessible thru the local area network?
Thanks for the reply
Current Code:
I haven't touched in webconfig
/// <summary>
/// Summary description for EDCService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class EDCService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
return "Hello World";
}
}
app MOVE TO IIS UPDATE:
ERROR
HTTP Error 500.21 - Internal Server Error
Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

Related

Connecting Android app to ASP.NET web service: java.net.MalformedURLException: Protocol not found

I am learning how to connect an Android app to ASP.NET web service from an online tutorial. When learning, I replaced their web service with one I had written on my own and ran it on a PC from Visual Studio. Then, I called the method 'Add' in the web service from the Android app but I am getting this error:
java.net.MalformedURLException: Protocol not found
I believe there is something wrong with the SOAP_ADDRESS field below.
public final String SOAP_ACTION = "http://tempuri.org/Add";
public final String OPERATION_NAME = "Add";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "12.145.142.45:50428/WebService.asmx";
This is the code of my web service.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public int Add(int a, int b)
{
return a+b;
}
}
I think the error is showing up because I cannot specify IP addresses like that directly in Java code. So, my question is what is the correct SOAP_ADDRESS value for connecting the Android app to my ASP.NET web service?

Display of webservice description

I am after teaching myself Soap Services in asp.net / c#. This a very simple and straightforward little service.
I have one problem, I would like to have a description in what the service does; what the parameters are and what the expected out come is.
How do you this part of webservice?
Here is the Code
[WebMethod]
public Boolean IsLessThan(Int64 userVariable, Int64 rangeLimit)
{
return (rangeLimit > userVariable);
}
This might help achieve what you want.
namespace WebApplication1
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/", Description = "Something about your service")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod(Description = "What this method does")]
public string HelloWorld()
{
return "Hello World";
}
}
}
Notice that both WebServiceAttribute and WebMethodAttribute have a description property, that will show up in the page.
Now to the point #John Saunders presented, it is true that "old school" web services are not in favor anymore (I would not go as far as saying you should not use it), and you are better off using the other techs (WCF, Web Api), and depending in what you want to achieve one is better(easier) then the other. So I would take a look at that, and see if you really want to invest your time "old school" web services.
Hope this helps

ASMX web service not generating async functions

I made a c# web service (new website > asp.net web service) with 1 function that was auto generated :
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public string Hello()
{
return "Hello User";
}
}
I also made a winform app and added a reference to that service and tried to call HelloWorldAsynch but all I had was HelloWorld
new ServiceReference1.Service1SoapClient().HelloWorldAsynch?
Does anyone know why is this happening?
It seems the problem is that I added the web service as a service reference and not as a web reference
Fix : http://msdn.microsoft.com/en-us/library/bb628649.aspx

instantiating an object from a web service vs instantiating an object from a regular class

I have a very basic web service:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
public int myInt = 0;
[WebMethod]
public int increaseCounter()
{
myInt++;
return myInt;
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
when I run that project my browser opens showing me the service:
on a different solution: (console application)
I am able to connect to that service by adding the reference:
then click on the add web reference button:
Lastly I type the url of the service I just created:
Now I am able to instantiate an object from the class Service1 from my console application as:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
localhost.Service1 service = new localhost.Service1();
// here is the part I don't understand..
// from a regular class you will expect myInt to increase every time you call
// the increseCounter method. Even if I call it twice I always get the same result.
int i;
i=service.increaseCounter();
i=service.increaseCounter();
Console.WriteLine(service.increaseCounter().ToString());
Console.Read();
}
}
}
why does myInt does not increase every time I call the increaseCounter method? every time I call that method it returns 1.
Services created through the older .asmx technology are not singleton instances. This means that each call you make to the server instantiates a new instance of the service each time. Two real solutions, either use static variables (eugh....), or switch to using WCF.
Becaue on the server side the class is created and disposed with EVERY call you make from the client... your client is just a "proxy" and doesn't correspond directly to an instance on the server side...
You can either make myInt static or make the server side service class a Singleton... both options would mean that myIntis shared across ALL client... or you could implement some session management to achieve a client-specific myInt... using WCF for the server side seems IMHO the best solution - it comes with configurable options for singleton, session management etc.
EDIT - as per comments:
With WCF you can have .NET-clients with session management which in turn allows you to have different (client-specific) values for myInt...
webservice instance is destroyed at the end of each method call, so that's why you always get the same result. You need some way to persist that value.

WCF REST service doesn't work on an IIS6 virtual server

Problem is I have a very simple WCF REST service, which I wrote starting from the WCF Service application template.
I have one method, one class set up like this
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class MainService
{
[WebGet(UriTemplate = "{ricCode}")]
public IdentifierInfo GetByRicCode(string ricCode)
{
...
}
}
When ran from my machine I have no problems it works fine (typical).
My problem is that when I publish this to a website on IIS6 (set up for anonymous access and on a virtual server) all I get from the above method is a 400 - invalid request.
When I changed the method as a test to this
[WebGet(UriTemplate = "")]
public string GetByRicCode()
{
return "foo";
}
and ran in on the IIS6 server it worked fine.
Maybe I set up the virtual server wrong on IIS... any ideas please?
I figured out the problem, it was throwing an exception due to nested web.configs
How annoying.

Categories