ASMX web service not generating async functions - c#

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

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

HTTP status 404 error while calling WCF service from ASP.NET client after web service migration from ASP.NET to WCF

Currently we have a number of customers which use ASP.NET clients to call our various ASP.NET Web Services. We would like to migrate web services to WCF without touching customers' clients and their proxies. In addition we want to avoid using IIS for hosting services.
I've prepared simple prototype to examine if we are able to achieve such migration. This prototype works fine if only a simple namespace of web service is in use e.g. test.com. But because our ASP.NET services have namespaces like test.com/app1, test.com/app2 etc we need to build WCF services accordingly. Unfortunately when such address is used I get HTTP status 404 error while calling service's method.
After a few days of struggling I'm not sure if such migration is possible without hosting services on IIS (the IIS solution is http://msdn.microsoft.com/en-us/library/aa738697(v=vs.100).aspx).
Please, follow steps which I've done to prepare working prototype (with namespace test.com) and tell me where I'm wrong for extended namespace (like test.com/app).
1.
Initial ASP.NET web service:
[WebService(Namespace = "http://test.com")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class AspNetWebService : WebService
{
private static int _counter = 0;
[WebMethod]
public int Increment()
{
return _counter++;
}
}
2.
Deploy web service on IIS 7.0.
3.
Create simple ASP.NET client and generate proxy to web service (from step 1) by adding web reference in Visual Studio 2012 to asmx file of web service.
4.
Client calls Increment method properly, so I will not change this client to check if I may call WCF service.
5.
Create WCF service.
Contract:
[ServiceContract(Name = "IncrementService", Namespace = "http://test.com")]
public interface IIncrementService
{
[OperationContract(Action = "http://test.com/Increment")]
int Increment();
}
Service:
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class IncrementService : IIncrementService
{
private static int _counter = 0;
public int Increment()
{
return _counter++;
}
}
Self hosted in:
static void Main(string[] args)
{
const string httpAddress = "http://test.com";
var host = new ServiceHost(typeof(IncrementService), new Uri(httpAddress));
try
{
var metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metadataBehavior == null)
metadataBehavior = new ServiceMetadataBehavior();
metadataBehavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(metadataBehavior);
var httpBinding = new BasicHttpBinding();
httpBinding.Security.Mode = BasicHttpSecurityMode.None;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
host.AddServiceEndpoint(typeof(IIncrementService), httpBinding, httpAddress);
host.Open();
Console.ReadLine();
host.Close();
}
catch (Exception ex)
{
Console.WriteLine("An exception occurred: {0}", ex.Message);
host.Abort();
}
}
6.
Switch off IIS to be sure that ASP.NET web service doesn't work and start WCF service.
7.
Run the same client as before (without any changes or proxy regenerations) - it calls Increment properly.
So far so good... now I extend namespace.
8.
Add app name to namespace in ASP.NET web service as following:
[WebService(Namespace = "http://test.com/app")]
Switch on IIS again, switch off WCF service, regenerate proxy for client to work with new namespace - it calls Increment method properly again.
Change namespaces in WCF service as following:
Contract:
[ServiceContract(Name = "IncrementService", Namespace = "http://test.com/app")]
public interface IIncrementService
{
[OperationContract(Action = "http://test.com/app/Increment")]
int Increment();
}
In host application change httpAddress:
const string httpAddress = "http://test.com/app";
Switch off IIS, start WCF.
Try to call Increment method from the same client - exception occurs: The request failed with HTTP status 404: Not Found.
If I do not change httpAddress in step 10, then all works fine, but in such case I can host only one service on test.com domain. So this solution is not sufficient for us.
Finally I found the solution.
The httpAddress in step 10 should be set the same as URL of ASP.NET Web Service taken from ASP.NET client generated in step 3.
In my case, the URL of Web Service is (you may find it in client's app.config):
http://192.168.1.2/WS_simple/AspNetWebService.asmx
where WS_simple is ASP.NET application name hosted in IIS (created in step 2)
So I changed httpAddress to:
http://localhost/WS_simple/AspNetWebService.asmx
Maybe it's not nice address of WCF service but it works. So migration to WCF service without IIS with backward compatibility is done :)

Access Web Service via Local Area Network

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

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