Click here to Skip to main content
15,884,893 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I'm trying to pass a variable to a simple ASP.NET 4.0 Web Service and get it to return the value, but I'm having no luck. I've been on this for 4 days now, browsed a lot of articles (including articles on this site) but I'm still no closer to the answer.

Here is my simple Web Service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace WebApplication2
{
    [WebService(Namespace = "http://tempuri.org/")]
    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class WebService1 : System.Web.Services.WebService
    {
        [WebMethod(MessageName = "HelloWorld")]
        public string HelloWorld(string myReturnString)
        {
            return "this is the returned parameter text from my web service : " + myReturnString;
        }
    }
}



And here is my Java class:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

public class WebService1
{
        private static String ENCODING_STYLE_PROPERTY =
 "javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD =
 "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING =
 "http://schemas.xmlsoap.org/soap/encoding/";
    private static QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
    public static void main(String[] args)
    {
        try
        {
            Service service = new Service();
            Call call = (Call) service.createCall();
                    call.setTargetEndpointAddress(new java.net.URL(
"http://localhost:2855/WebService1.asmx"));
                    call.setOperationName(new QName("http://tempuri.org/","HelloWorld"));
                    call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
                    call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
                    call.setProperty(ENCODING_STYLE_PROPERTY,
URI_ENCODING);
                    call.setReturnType(QNAME_TYPE_STRING);
                    call.addParameter("myReturnString", QNAME_TYPE_STRING,ParameterMode.IN);
                    String[] params = { "some value" };
                    String result = (String)call.invoke(params);
            System.out.println("\n" + result);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}



What's infuriating is that it connects to the service fine, but when it returns, it only returns the text "this is the returned parameter text from my web service : " and my parameter always returns null. Why won't it pick up my parameter? I'm sure there's just a simple setting missing or something but I can't see what it is. :confused:

Many thanks in advance for your help


Nick
Posted
Comments
Nagy Vilmos 5-Nov-10 5:53am    
Is this still a problem?
amarasat 17-Nov-10 16:51pm    
Were u able to resolve this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900