求助!!!急!!在线等。C#动态调用Java Web Service问题

RubenLuLu 2014-05-15 10:41:40



public static object InvokeWebService(string url, string classname, string methodname, object[] args)
{
string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
if ((classname == null) || (classname == ""))
{
classname = WSHelper.GetWsClassName(url);
}
try
{ //获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url);
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider icc = new CSharpCodeProvider();
//设定编译参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = true;
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll");
//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);
return mi.Invoke(obj, args);
// PropertyInfo propertyInfo = type.GetProperty(propertyname);
//return propertyInfo.GetValue(obj, null);
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
}
}


这是调用

string url = "http://localhost:8080/Test/TestClassPort?wsdl";
string[] args = new string[1];
args[0] = "111";
object result = WSHelper.InvokeWebService(url, "TestWebService", args);
DataSet ds = (DataSet)result;


死在这一句Type t = assembly.GetType(@namespace + "." + classname, true, true);

具体提示错误是:
未能从程序集“tt11kcis, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”中加载类型“EnterpriseServerBase.WebService.DynamicWebCalling.TestClassPort?wsdl”。


我尝试用过直接引用服务去调用那个Web Service 发现怎么都不能成功,添加了服务引用以后我看到别人写法是可以直接把它实例化的 而我我去实例化的时候 系统提示是命名空间
我只有这样写才不报错。。。但是这完全不是我要的。。
//ServiceReference1.TestClassDelegate xx = new ServiceReference1.TestClassDelegateClient();
//ServiceReference1.TestWebServiceRequest rr = new ServiceReference1.TestWebServiceRequest();
//xx.TestWebService(rr);


求解决办法,不论是建议用中间件还是能解决现有问题都可以。。。如果建议用中间件请提供具体内容
...全文
1516 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
姜老大 2016-08-23
  • 打赏
  • 举报
回复
java 生成的webservice 会生成wsdl 文件 在用浏览器访问 webservice url 时,如果生成了wsdl 文件,则浏览器会直接访问wsdl文件内容 而我用 wsgen 生成的wsdl文件 是一组 1) *.wsdl 2) *.xsd 要把 这一组文件整理成一个文件,c# 动态解析函数“InvokeWebService” 才能正确解析 即 要把 wsdl 中节点 <xsd:schema> <xsd:import namespace="http://www.dectech.com" schemaLocation="HelloService_schema1.xsd"/> </xsd:schema> 用*.xsd 文件内容替换
RubenLuLu 2014-05-15
  • 打赏
  • 举报
回复
public string TestWebService(string arg0)
    {
        TestWebServiceRequest inValue = new TestWebServiceRequest();
        inValue.Body = new TestWebServiceRequestBody();
        inValue.Body.arg0 = arg0;
        TestWebServiceResponse retVal = ((TestClassDelegate)(this)).TestWebService(inValue);
        return retVal.Body.@return;
    }
这是生成的方法。。我跟踪调试到方法里来, 在红色处断点。。但是。调试不到下一句就挂了。
RubenLuLu 2014-05-15
  • 打赏
  • 举报
回复
补充, 将生成的文件中的config 更名为 app.config以后。实例化不再出错。但是调用依然出错。。
RubenLuLu 2014-05-15
  • 打赏
  • 举报
回复
求解 生成 TestClassService.cs 以后。
TestClassDelegateClient xx = new TestClassDelegateClient();
string xx1 = xx.TestWebService("aa");
实例化阶段就报错拉。
feiyun0112 2014-05-15
  • 打赏
  • 举报
回复
开始菜单--Visual Studio xxx--Visual Studio Tools-- VS 开发人员命令提示
RubenLuLu 2014-05-15
  • 打赏
  • 举报
回复
OK 已用Vs带的那个命令提示生成完毕。尝试中
RubenLuLu 2014-05-15
  • 打赏
  • 举报
回复
svcutil 不是内部或外部命令
RubenLuLu 2014-05-15
  • 打赏
  • 举报
回复
引用 2 楼 feiyun0112 的回复:
运行开发人员工具提示 输入命令行 svcutil http://localhost:8080/Test/TestClassPort?wsdl 生成客户端
在哪里运行? C#端?
feiyun0112 2014-05-15
  • 打赏
  • 举报
回复
运行开发人员工具提示

输入命令行

svcutil http://localhost:8080/Test/TestClassPort?wsdl

生成客户端
RubenLuLu 2014-05-15
  • 打赏
  • 举报
回复
曾经如此辉煌的论坛。。就这样。放弃等了。搜索中间件去了。

12,165

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧