Posted by: Nishant Rana | July 2, 2008

Calling a asp.net webservice from an asp page

Say we have created a simple web service like this

[WebMethod]
public string Hello(String name) {
return “Hello “+name ;
}

Now we want to call the web service from inside our asp page,

for this we can make use of the following code

<%
Dim myPostData
Dim name
name=”Mickey Mouse”
myPostData=”name=” & name
Dim xmlhttp
Dim postUrl
postUrl = “http://servername/MyService/Service.asmx/Hello”
Set xmlhttp = server.Createobject(“MSXML2.XMLHTTP”)
xmlhttp.Open “POST”,postUrl,false
xmlhttp.setRequestHeader “Content-Type”,”application/x-www-form-urlencoded”
xmlhttp.send strWebServideDetails
Response.Write(“<b>This is the message i recieved</b>” +xmlhttp.responseText)

%>

Bye


Responses

  1. i’m gettin the error bellow:

    This is the message i recieved
    Erro de Servidor no Aplicativo ‘/IServiceWS’.
    ——————————————————————————–

    Formato da solicitação não reconhecido.
    Descrição: Ocorreu uma exceção não tratada durante a execução da atual solicitação da Web. Examine o rastreamento de pilha para obter mais informações sobre o erro e onde foi originado no código.

    Detalhes da Exceção: System.InvalidOperationException: Formato da solicitação não reconhecido.

    Erro de Origem:

    Exceção não tratada foi gerada durante a execução da atual solicitação da Web. As informações relacionadas à origem e ao local da exceção podem ser identificadas usando-se o rastreamento de pilha de exceção abaixo.

    Rastreamento de Pilha:

    [InvalidOperationException: Formato da solicitação não reconhecido.]
    System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +388
    System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +94
    System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, String path, String pathTranslated, Boolean useAppConfig) +699
    System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +95
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +173


Leave a response

Your response:

Categories