当前位置: 代码迷 >> Web Service >> java调用.net的WS,参数没法读取到
  详细解决方案

java调用.net的WS,参数没法读取到

热度:325   发布时间:2013-01-04 10:04:12.0
java调用.net的WS,参数无法读取到
如题,我把c#写的WS代码贴出来
  [SoapRpcMethod(Action = "http://www.56rh.com/WS/getName", RequestNamespace = "http://www.56rh.com/WS/", ResponseNamespace = "http://www.56rh.com/WS/", Use = System.Web.Services.Description.SoapBindingUse.Literal)]
         [WebMethod(Description = "")]
         public string getName(string name)
         {
             writefile(name);
             return "Hello" + name;
           
         }
我写了这个简单的例子,writefile为读取参数写入本地txt,java端调用我WS始终返回hello.查看txt显示参数name为空。
有人遇到过这样的情况么
------解决方案--------------------
累不累啊?

你可以先写一个ashx,例如
<%@ WebHandler Language="C#" Class="HelloJava" %>

using System;
using System.Web;

public class HelloJava : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello " + context.Request.QueryString["name"]);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}


先把web service扔到脑后。
------解决方案--------------------
引用:
引用:

怎么也得检查java代码啊

java端不是很懂,我就把java端的代码贴出来
import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class……


试了下,你把 new Object[] { name } 拿出来单独定义再传入。。。就好了。
付一个我调用 WebXml 的示例。

String endPoint = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
        Service service = new Service();

        Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(endPoint);

        String namespace = "http://WebXml.com.cn/";
        call.addParameter(new QName(namespace, "mobileCode"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.addParameter(new QName(namespace, "userID"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.setReturnClass(java.lang.String.class);

        String oName = "getMobileCodeInfo";
        call.setUseSOAPAction(true);
  相关解决方案